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

VirtualItemCount and Filtering

6 Answers 216 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 18 Mar 2013, 08:37 PM
Hi,

I have a programatically created RadGrid with custom paging enabled, which works fine. However the grid also has filtering enabled, and when a user changes the filter values the pages at the bottom reflect the number of pages before filtering - so essentially I need to somehow set the VirtualItemCount with the correct number of rows.

How would I do this?

6 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 21 Mar 2013, 04:32 PM
Hello Chris,

In order to give you a precise suggestion on how to resolve the problem I would like to know what type of data source are you using. Could you please show us some code samples? Once we get a better understanding over the implementation we would be able to give you a more straight to the point answer.

Kind regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Chris
Top achievements
Rank 1
answered on 22 Mar 2013, 03:32 PM
No problem, here's my code:

 private RadGrid gvProductRange { get { return (RadGrid)plcProductRange.FindControl("gvProductRange"); } }<br>     <br> protected void Page_Init(object sender, EventArgs e)
        {
            DefineStructure();
        }

        
private void DefineStructure()
        {
            WDBDataContext dc =
new WDBDataContext();
            RadGrid gvProductRangeTmp =
new RadGrid();
            gvProductRangeTmp.ID =
"gvProductRange";
            gvProductRangeTmp.DataBound += gvProductRange_DataBound;
            gvProductRangeTmp.ItemDataBound += gvProductRange_ItemDataBound;
            gvProductRangeTmp.NeedDataSource += gvProductRange_NeedDataSource;
            gvProductRangeTmp.AllowCustomPaging =
true;
            gvProductRangeTmp.AllowFilteringByColumn =
true;
            gvProductRangeTmp.AllowPaging =
true;
            gvProductRangeTmp.AllowSorting =
true;
            gvProductRangeTmp.AutoGenerateColumns =
false;
            gvProductRangeTmp.PageSize = 50;
            gvProductRangeTmp.MasterTableView.AllowCustomPaging =
true;
            gvProductRangeTmp.MasterTableView.AllowSorting =
true;
            gvProductRangeTmp.MasterTableView.AllowPaging =
true;
            gvProductRangeTmp.MasterTableView.AllowFilteringByColumn =
true;
            gvProductRangeTmp.MasterTableView.PageSize = 50;
            gvProductRangeTmp.GroupingSettings.CaseSensitive =
false;
            gvProductRangeTmp.Columns.Add(
new GridBoundColumn() { UniqueName = "ProductRange", HeaderText = "Product Range", AutoPostBackOnFilter = true, DataField = "ProductRange", AllowFiltering = true });
            gvProductRangeTmp.Columns.Add(
new GridBoundColumn() { UniqueName = "Product", HeaderText = "Product", AutoPostBackOnFilter = true, DataField = "Product", AllowFiltering = true });
            gvProductRangeTmp.Columns.Add(
new GridBoundColumn() { UniqueName = "ProductType", HeaderText = "Product Type", AutoPostBackOnFilter = true, DataField = "ProductType", AllowFiltering = true });
            gvProductRangeTmp.Columns.Add(
new GridBoundColumn() { UniqueName = "Dimensions", HeaderText = "Dimensions", AutoPostBackOnFilter = true, DataField = "Dimensions", AllowFiltering = true });
            gvProductRangeTmp.Columns.Add(
new GridBoundColumn() { UniqueName = "Material", HeaderText = "Material", AutoPostBackOnFilter = true, DataField = "Material", AllowFiltering = true });
            gvProductRangeTmp.Columns.Add(
new GridNumericColumn() { UniqueName = "TradePrice", HeaderText = "Trade Price", AutoPostBackOnFilter = true, DataField = "TradePrice", FilterControlWidth = Unit.Pixel(50), DataFormatString = "{0:c}", AllowFiltering = true, NumericType = NumericType.Currency });
           
    List<Wholesaler> wholesalerList = dc.Wholesalers.ToList();
            
foreach (Wholesaler wholesaler in wholesalerList)
            {
                gvProductRangeTmp.Columns.Add(
new GridNumericColumn() { UniqueName = wholesaler.ID.ToString(), AllowFiltering = false, NumericType = Telerik.Web.UI.NumericType.Currency, HeaderText = wholesaler.Name, DataField = wholesaler.ID.ToString(), DataFormatString = "{0:c}" });
            }

            plcProductRange.Controls.Add(gvProductRangeTmp);
        }

        
private DataTable BindGrid(int startIndex, int pageSize)
        {
            DataTable dt =
new DataTable();
            dt.Columns.Add(
"ProductRange", typeof(string));
            dt.Columns.Add(
"Product", typeof(string));
            dt.Columns.Add(
"ProductType", typeof(string));
            dt.Columns.Add(
"Dimensions", typeof(string));
            dt.Columns.Add(
"Material",typeof(string));
            dt.Columns.Add(
"TradePrice", typeof(decimal));

            
//Long code to get data here

    return dt;
        }

        protected void gvProductRange_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            if (Session["ActiveRevision"] != null)
            {
                WDBDataContext dc = new WDBDataContext();
                int startRowIndex = gvProductRange.CurrentPageIndex * gvProductRange.PageSize;
                int maxRows = gvProductRange.PageSize;
                DataTable dt = BindGrid(startRowIndex, maxRows);
                gvProductRange.VirtualItemCount = dc.Luc_ItemDetails.Count();
                gvProductRange.MasterTableView.VirtualItemCount = gvProductRange.VirtualItemCount;
                gvProductRange.DataSource = dt;
           }
        }
0
Angel Petrov
Telerik team
answered on 27 Mar 2013, 04:11 PM
Hello Chris,

Thank you for providing a code samples. Since you are using advanced data binding I suggest that you apply the filtering on a data level. Is this applicable in your case? Can you modify your logic so that it returns a filtered set of data to which you can later bind the grid?

As for setting the VirtualItemCount you will have to do this in the NeedDataSource event handler. Additionally note that you can use the result returned from the BindGrid method which returns a DataTable. You can get the number of records by calling DataTable.Rows.Count.

I strongly suggest that you review this online demo in which demonstrates a possible resolution of your problem.

All the best,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Marius
Top achievements
Rank 1
answered on 25 Jun 2017, 09:47 AM
12
0
Marius
Top achievements
Rank 1
answered on 25 Jun 2017, 09:48 AM

0 posta

 

0
Marius
Top achievements
Rank 1
answered on 25 Jun 2017, 09:50 AM
12345
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Chris
Top achievements
Rank 1
Marius
Top achievements
Rank 1
Share this question
or