How to set default value to filter the rows in RadGrid?

2 posts, 0 answers
  1. Uli
    Uli avatar
    12 posts
    Member since:
    Sep 2019

    Posted 27 Aug Link to this post

    I have a combobox as filter in RadGrid. The combobox has "Alle"(all), "Nein"(no), "Ja"(yes) . The "Alle" was default. The page shows all 75 rows after loaded.

    I want to have "Ja" as default and to show the 73 rows with "Ja". So I added OnLoad="cboFilterFormActive_Load" in the RadComboBox and a C# method cboFilterFormActive_Load(...).

    The aspx code now is like:

    <telerik:RadGrid ID="radGridForms" runat="server"
                     DataSourceID="SqlDataSource_Grid" AllowSorting="true" AllowPaging="true" PageSize="10" AllowFilteringByColumn="true"
                     OnDataBound="radGridForms_DataBound">
        <MasterTableView AutoGenerateColumns="false" AllowMultiColumnSorting="true">
            <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false" ShowRefreshButton="false" />
            <Columns>
                <telerik:GridTemplateColumn DataField="FormKey" UniqueName="FormKey">
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="visible" HeaderText="aktiv" UniqueName="FormActive">
                    <FilterTemplate>
                        <telerik:RadComboBox ID="cboFilterFormActive" runat="server" RenderMode="Lightweight"
                                             Skin="Bootstrap" Width="100%" ToolTip="Filter Formular aktiv"
                                             DataSourceID="SqlDataSource_FilterFormActive" DataTextField="visible" DataValueField="visible"
                                             AppendDataBoundItems="false"
                                             SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("FormActive").CurrentFilterValue %>'   
                                             OnClientSelectedIndexChanged="visibleComboIndexChanged"
                                             OnItemDataBound="cboFilterFormActive_ItemDataBound"
                                             OnLoad="cboFilterFormActive_Load">
                        </telerik:RadComboBox>
                        <telerik:RadScriptBlock ID="RadScriptBlockFilterVisible" runat="server">
                            <script type="text/javascript">
                                function visibleComboIndexChanged(sender, args) {
                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                    tableView.filter("FormActive", args.get_item().get_value(), "EqualTo");
                                }
                            </script>
                        </telerik:RadScriptBlock>
                    </FilterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblFormVisible" runat="server" Text='<%# translateBool(Eval("visible")) %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
            <PagerStyle Position="TopAndBottom" AlwaysVisible="true" />
        </MasterTableView>
        <SortingSettings SortedBackColor="#EDEDED" EnableSkinSortStyles="false"></SortingSettings>
        <FilterMenu Skin="Bootstrap" EnableEmbeddedSkins="false" RenderMode="Lightweight"></FilterMenu>
    </telerik:RadGrid>

     

    a new mothod in aspx.cs:

            protected void cboFilterFormActive_Load(object sender, EventArgs e)
            {
                var combo = (RadComboBox)sender;
                RadComboBoxItem itm = combo.FindItemByText("Ja");
                if (itm !=null)
                    itm.Selected = true;
            }

     

    The "Ja" is now default in the Combobox. But it doesn't filter. All the 75 values are shown after loading page. How can I make it filter "Ja" out?

  2. Uli
    Uli avatar
    12 posts
    Member since:
    Sep 2019

    Posted 28 Aug in reply to Uli Link to this post

    My solution is 

    in aspx:

    <telerik:RadGrid ...>

                        <ClientSettings>
                            <ClientEvents OnGridCreated="TableCreated"/>
                        </ClientSettings>

    </telerik:RadGrid>

    <telerik:RadScriptBlock  ID="RadCodck1" runat="server">
                        <script type="text/javascript">                       
                            function TableCreated() {
                                var fl = sessionStorage.getItem("pageloaded");                            
                                if (fl === null) {
                                    var tableView = $find("<%= radGridForms.ClientID %>").get_masterTableView();
                                    tableView.filter("FormActive", 1, "EqualTo"); // "Ja" has index 1
                                    sessionStorage.setItem("pageloaded", true);
                                }
                            }
                        </script>
    </telerik:RadScriptBlock> 

    in js:

    when page is closing 

    function (e)  {
        sessionStorage.removeItem("pageloaded");
    });

     

     

Back to Top