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

Filter on Radgrid results

3 Answers 155 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 25 Aug 2016, 09:00 PM
Hello,
I want to users to be able to filter on the results in our radgrid. I enabled AllowFilteringbycolumn = "true' on my radgrid, but whenever I enter a value into the new radgrid filter boxes the loading panel spins and nothing changes. I have a searchbox that allows the user to search for their items. After that initial query returns, I want them to be able to filter on any column in the grid. So for instance if the results show all of their items, but they want to see all of them in building 1, they should be able to enter 1 into the filter textbox on the grid. How can I make this happen?

Thank you!
<telerik:RadGrid ID="RadGrid1" runat="server" EnableLinqExpressions="false" AutoGenerateColumns="true" Skin="WebBlue" AllowPaging="true" AllowSorting="true" CellSpacing="0" GridLines="Both" OnNeedDataSource="NeedDataSource" PageSize="50" OnPreRender="RadGrid1_PreRender"  AllowMultiRowSelection="false" AllowFilteringByColumn="true">
                <PagerStyle Mode="NextPrevAndNumeric" />
                <ItemStyle CssClass="UsePointer" />
                <MasterTableView CommandItemDisplay="bottom">
                    <SortExpressions><telerik:GridSortExpression FieldName="assetTag" SortOrder="Ascending" /></SortExpressions>
                    <Columns>
                        <telerik:GridTemplateColumn HeaderStyle-CssClass="commandHeader" HeaderStyle-Width="30px" Exportable="false" UniqueName="checkCol">
                            <HeaderTemplate>
                                <asp:CheckBox ID="checkAll" runat="server" onclick="CheckAll(this)" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="cboxSelect" runat="server" onclick="unCheckHeader(this); enableMassUpdate()" OnCheckedChanged="GridCheckBoxChanged" />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                    <CommandItemSettings ShowExportToExcelButton="false" ShowAddNewRecordButton="false" ShowRefreshButton="false"/>
                </MasterTableView>
                <ClientSettings AllowKeyboardNavigation="true"  EnablePostBackOnRowClick="true" >
                    <Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
                    <Selecting AllowRowSelect="true" />
                    <ClientEvents  OnRowSelecting="RowSelecting" OnRowSelected="RowSelected" OnCommand="ClearForm"  />
                    <KeyboardNavigationSettings EnableKeyboardShortcuts="false" AllowSubmitOnEnter="false" AllowActiveRowCycle="false" ></KeyboardNavigationSettings>
                </ClientSettings>
            </telerik:RadGrid>

protected void NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {

            (source as RadGrid).DataSource = getDataGrid("RadGrid1");
        }

protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridColumn checkCol = RadGrid1.MasterTableView.GetColumnSafe("checkCol");
                checkCol.OrderIndex = 1;
                GridColumn assetDeptCol = RadGrid1.MasterTableView.GetColumn("itemDept");
                assetDeptCol.HeaderStyle.Width = Unit.Pixel(115);
                assetDeptCol.HeaderText = "item Department";
                assetDeptCol.OrderIndex = 2;
                GridColumn assetTagCol = RadGrid1.MasterTableView.GetColumn("itemTag");
                assetTagCol.HeaderStyle.Width = Unit.Pixel(100);
                assetTagCol.HeaderText = "itemTag";
                assetTagCol.OrderIndex = 3;
                GridColumn employeeCol = RadGrid1.MasterTableView.GetColumn("employee");
                employeeCol.HeaderStyle.Width = Unit.Pixel(280);
                employeeCol.HeaderText = "Employee";
                employeeCol.OrderIndex = 4;
                GridColumn buildingCol = RadGrid1.MasterTableView.GetColumn("building");
                buildingCol.HeaderStyle.Width = Unit.Pixel(100);
                buildingCol.HeaderText = "Building";
                buildingCol.OrderIndex = 6;
                GridColumn floorCol = RadGrid1.MasterTableView.GetColumn("floor");
                floorCol.HeaderStyle.Width = Unit.Pixel(70);
                floorCol.HeaderText = "Floor";
                floorCol.OrderIndex = 7;
                GridColumn roomCol = RadGrid1.MasterTableView.GetColumn("room");
                roomCol.HeaderStyle.Width = Unit.Pixel(150);
                roomCol.HeaderText = "Room";
                roomCol.OrderIndex = 8;     
                RadGrid1.Rebind();
           }
}

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 30 Aug 2016, 01:01 PM
Hello Ryan,

Please temporarily disable any AJAX on the page if present (RadAjaxManager, RadAjaxPanel, UpdatePanel, etc.) and enable your script debugger (FireBug or F12) to see whether there are any script or server errors interfering, and make sure that the application works without AJAX.

I am also sending a sample RadGrid web site, which you can use for a starting reference.

Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Ryan
Top achievements
Rank 1
answered on 30 Aug 2016, 03:29 PM

Thank you Eyup for your reply. I will review your sample and try implementing your suggestions as soon as I can get the opportunity. 

One thing I would like to mention that may or may not be an issue. I see that you created a DataTable and the column.DataTypes in GetGridSource. The way our code is structed is that in our equivalent GetGridSource (getDataGrid), we created an IDatabase db connection and use sqlBuilder to populate our List.

Will it cause problems if I create the columns in our RagGrid1_PreRender and also in getDataGrid? Or can I just use code example in private DataTable GetGridSource() and use that in the PreRender?

Apologize for the basic questions, this is all new to me.

 

Thanks again,

Ryan

0
Eyup
Telerik team
answered on 05 Sep 2016, 06:22 AM
Hello Ryan,

Let's clear some things up with RadGrid:

1. DataBinding:

Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:

Declarative DataSource (DataSourceID property)
Programmatic Data Binding (NeedDataSource event, + DetailTableDataBind for hierarchy). You should set the DataSource property ONLY within these event handlers.

2. Defining columns:

Here
you have 3 options to choose from:
  • Remove the AutoGenerateColumns property and create the columns in the aspx page declaratively:

http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/basic-filtering/defaultcs.aspx

  • Keep the AutoGenerateColumns property and apply the columns settings using the ColumnCreated event handler:

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/columns/working-with-autogenerated-columns

  • Remove the AutoGenerateColumns property and create the columns in the code-behind programmatically

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically#creating-template-columns-programmatically


I hope the clarification was helpful.


Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Filter
Asked by
Ryan
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or