Scenario:
Grid with filtering on.
I turned off AutoPostBackOnFilter as I want the user to have to press the filter button to filter. However, once I turned AutoPostBackOnFilter off, clicking the Filter button poups a list of filtering functions to use first. I don't want this list to show up, and instead for the filter to use the function I set with the CurrentFilterFunction attribute. So as soon as the user clicks the filter button, it actually filters the grid.
How can I achieve this? I couldn't find any attribute that turns off the displaying of the filter functions. Thanks.
Grid with filtering on.
I turned off AutoPostBackOnFilter as I want the user to have to press the filter button to filter. However, once I turned AutoPostBackOnFilter off, clicking the Filter button poups a list of filtering functions to use first. I don't want this list to show up, and instead for the filter to use the function I set with the CurrentFilterFunction attribute. So as soon as the user clicks the filter button, it actually filters the grid.
How can I achieve this? I couldn't find any attribute that turns off the displaying of the filter functions. Thanks.
8 Answers, 1 is accepted
0
Accepted
Nikita Gourme
Top achievements
Rank 1
answered on 25 Aug 2010, 04:36 PM
Paul, based on my experience with the Telerik controls, I can propose the following solution:
- Wire the OnFilterMenuShowing event of the grid and cancel the action to stop the filter menu from showing
- Call the filter method from the client grid API with filter function and value of your choice similar to what is shown on this sample. The idea is to fetch the value from the filter control and trigger the filter manually taking advantage of the client API.
Hope this helps.
0
Paul J
Top achievements
Rank 1
answered on 25 Aug 2010, 04:42 PM
Nikita, thanks for the help. I'm going to try your suggestion out. It's a shame there is no simple "DiaplayFilterFunctions" attribute to set to true or false. I guess I'm the first to not want to display the filter options? I mean, considering they have the CurrentFilterFunction attribute, seems only fitting they'd have an option to not show the filters list.
Oh well, maybe they'll a new attribute for this in their next release.
Thanks.
Oh well, maybe they'll a new attribute for this in their next release.
Thanks.
0
Paul J
Top achievements
Rank 1
answered on 25 Aug 2010, 04:57 PM
Trying your suggestion Nikita, but it's seeming to be more trouble than it's worth. maybe telerik will answer with an 'easier' method. thanks though.
0
Accepted
Nikita Gourme
Top achievements
Rank 1
answered on 30 Aug 2010, 02:59 PM
Well, stopping the filtering menu from being displayed with a single line of code from the client event seems pretty easy. Here is what I have in mind (pardon me if the code is not 100% functional for your scenario):
ASPX/ASCX
<ClientEvents OnFilterMenuShowing =
"FilterMenuShowing"
...
JavaScript
<script type=
"text/javascript"
>
function
FilterMenuShowing(sender, eventArgs)
{
//stop the filter menu from being displayed
eventArgs.set_cancel(
true
);
//get the value from the filter textbox
var
gridDOMElement = $get(sender.get_id());
var
filterValue = $telerik.findElement(gridDOMElement,
"FilterTextBox_"
+ eventArgs.get_gridColumn().get_uniqueName()).value;
//trigger filtering operation for the active column. Replace the "Contains" filter function with other according to your preferences (EqualTo for integer column for example)
eventArgs.get_tableView().filter(eventArgs.get_gridColumn().get_uniqueName(), filterValue ,
"Contains"
)
}
</script>
0
Paul J
Top achievements
Rank 1
answered on 13 Sep 2010, 02:10 PM
Nikita, thanks for the answer. I apologize in my delay to responding. this seems to work great, except in the following scenarios:
1. user filters by a input, say they type in "Smith". the first time it filters fine. but if they re-click the filter icon button again (without changing the filter textbox's value) it throws a JavaScript error
2. the same JavaScript error is thrown too if the user clicks the filter icon button while the filter text box is empty.
JavaScript error:
Object doesn't support this property or method.
erring line: var filterValue = $telerik.findElement(gridDOMElement, "FilterTextBox_" + eventArgs.get_gridColumn().get_uniqueName()).value;
i took a look but couldn't figure out how to ignore the filter request if the value of the filter textbox is empty, and, if the user has populated the box simply re-run the filter even if the box contains the same value as the previous filter request.
make sense? thanks again for all your help.
1. user filters by a input, say they type in "Smith". the first time it filters fine. but if they re-click the filter icon button again (without changing the filter textbox's value) it throws a JavaScript error
2. the same JavaScript error is thrown too if the user clicks the filter icon button while the filter text box is empty.
JavaScript error:
Object doesn't support this property or method.
erring line: var filterValue = $telerik.findElement(gridDOMElement, "FilterTextBox_" + eventArgs.get_gridColumn().get_uniqueName()).value;
i took a look but couldn't figure out how to ignore the filter request if the value of the filter textbox is empty, and, if the user has populated the box simply re-run the filter even if the box contains the same value as the previous filter request.
make sense? thanks again for all your help.
0
Nikita Gourme
Top achievements
Rank 1
answered on 16 Sep 2010, 12:56 PM
Try to wrap the code line inside conditional block as follows:
if
(gridDOMElement && $telerik.findElement(gridDOMElement,
"FilterTextBox_"
+ eventArgs.get_gridColumn().get_uniqueName()).value)
{
var
filterValue = $telerik.findElement(gridDOMElement,
"FilterTextBox_"
+ eventArgs.get_gridColumn().get_uniqueName()).value;
//trigger filtering operation for the active column. Replace the "Contains" filter function with other according to your preferences (EqualTo for integer column for example)
eventArgs.get_tableView().filter(eventArgs.get_gridColumn().get_uniqueName(), filterValue ,
"Contains"
)
}
to see if this helps.
Also if you find my replies helpful, mark them as answers please.
0
Paul J
Top achievements
Rank 1
answered on 16 Sep 2010, 02:14 PM
Sorry, that didn't seem to work. Again, I'm getting the error:
Object doesn't support this property or method.
Even when I do just:
I still get the same error. It's like when the filter box contains the same value, or no value / empty string the eventArgs cannot call the .get_gridColumn().
So I was thinking maybe there's a specific value I could check eventArgs for to see if then the .get_gridColumn could be called ? but what value?
I do appreciate all the help you've been giving.
Object doesn't support this property or method.
Even when I do just:
if
(gridDOMElement && eventArgs.get_gridColumn()) {
I still get the same error. It's like when the filter box contains the same value, or no value / empty string the eventArgs cannot call the .get_gridColumn().
So I was thinking maybe there's a specific value I could check eventArgs for to see if then the .get_gridColumn could be called ? but what value?
I do appreciate all the help you've been giving.
0
Nikita Gourme
Top achievements
Rank 1
answered on 17 Sep 2010, 04:14 PM
Strange, I do not get that exception when I did a quick test. Put some breakpoints/debugger keywords in your javascript code to trace the reason for the error, then you will know how to eradicate it.