This is a migrated thread and some comments may be shown as answers.
How to set default value to filter the rows in RadGrid?
1 Answer 5 Views
This is a migrated thread and some comments may be shown as answers.
Uli
Top achievements
Rank 1
Uli asked on 27 Aug 2020, 07:49 AM

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?

1 Answer, 1 is accepted

Sort by
0
Uli
Top achievements
Rank 1
answered on 28 Aug 2020, 07:35 AM

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");
});

 

 

Asked by
Uli
Top achievements
Rank 1
Answers by
Uli
Top achievements
Rank 1
Share this question
or