This is a migrated thread and some comments may be shown as answers.

Customize Filtering options

2 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anzar
Top achievements
Rank 2
Anzar asked on 19 Sep 2012, 10:48 AM
Hi,
 How to customize the filtering options of telerik rad grid? I wanto set some options in the filter menu. For example only Contains & Like.
If there is any way to set filtermenu options(Contains , Like, Greater than etc) based on the column data type.

Thanks & Regards
Anzar.M

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Sep 2012, 11:03 AM
Hi,

You can try the client side approach to limit the filter options displayed for a given column. Intercept the OnFilterMenuShowingclient event of RadGrid and hide some of the possible choices from within the body of the respective handler.Below is a sample code that customizes the filter menu options for columns according to data type.
aspx:
<telerik:RadGrid AutoGenerateColumns="false" ID="RadGrid1" DataSourceID="SqlDataSource1"
 AllowFilteringByColumn="True" runat="server" EnableLinqExpressions="false">
    <MasterTableView >
            <Columns>
                 . . ..
            </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnFilterMenuShowing="filterMenuShowing" />
    </ClientSettings>
<FilterMenu OnClientShown="MenuShowing" />
</telerik:RadGrid>
JS:
<script type="text/javascript">
    var column = null;
    function MenuShowing(sender, args) {
        if (column == null) return;
        var menu = sender; var items = menu.get_items();
        if (column.get_dataType() == "System.String") {
            var i = 0;
            while (i < items.get_count()) {
                if (!(items.getItem(i).get_value() in { 'NoFilter': '', 'Contains': '', 'NotIsEmpty': '', 'IsEmpty': '', 'NotEqualTo': '', 'EqualTo': '' })) {
                    var item = items.getItem(i);
                    if (item != null)
                        item.set_visible(false);
                }
                else {
                    var item = items.getItem(i);
                    if (item != null)
                        item.set_visible(true);
                } i++;
            }
        }
        if (column.get_dataType() == "System.Int64") {
            var j = 0; while (j < items.get_count()) {
                if (!(items.getItem(j).get_value() in { 'NoFilter': '', 'GreaterThan': '', 'LessThan': '', 'NotEqualTo': '', 'EqualTo': '' })) {
                    var item = items.getItem(j); if (item != null)
                        item.set_visible(false);
                }
                else { var item = items.getItem(j); if (item != null) item.set_visible(true); } j++;
            }
        }
        column = null;
        menu.repaint();
    }
    function filterMenuShowing(sender, eventArgs) {
        column = eventArgs.get_column();
    }
</script>

Thanks,
Shinu.
0
Anzar
Top achievements
Rank 2
answered on 19 Sep 2012, 11:35 AM
HI,

I have a problem. On combox template columns, i stored DataTextField="NAME"(string) and DataValueField="ID"(Numeric). And also Checkbox columns in my grid. In this situations waht i do?

Thanks & Regards
Anzar.M
Tags
Grid
Asked by
Anzar
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Anzar
Top achievements
Rank 2
Share this question
or