Customize Filtering options

3 posts, 0 answers
  1. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 19 Sep 2012 Link to this post

    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. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Sep 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 19 Sep 2012 Link to this post

    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
Back to Top