Hi,
I am using ASP.Net MVC & IgniteUI.
I have a grid that displays paged data. The paging is remote & by that I mean that the whole result is not fetched at once in the form of IQueryable result set. I have Sql query that pulls only the requested page data by using the PageSize & PageIndex properties of the grid.
Therefore the datasource of the grid knows only about tha data which is currently being displayed on the page and not the whole dataset.
Now I want to use remote filtering, Here I want the remote filtering to search for data in the whole table of the database rather than only the displayed page of the grid.
In Remote Paging I used PageSize & PageIndex property to pull only the requested page of the grid.
How can I search the whole table for the matching data rather than only the current page data ? Do I have to construct the query myself or will IgGrid provide this functionality like it does in Local Filtering? In Local Filtering only the paged data is searched, I want to search all the pages of my grid but the problem is only the current page is the datasource of the grid and hence the grid does not know about other pages.
How can I achieve this? Please provide a short sample if you can, that would be really helpful.
Hello Omer ,
Thank you for posting in our forum.
In general the grid does have a way to handle all remote operations. However that would require to set the [DataSourceAction] attribute for the Action that the DataSourceURL option points to.
In that case the whole data will need to be returned in the View .That attributes ([DataSourceAction] ) serves as an Action Filter and will apply the additional processing of the data based on the sorting, paging, filtering data passed as part of the Query string of the request. There a similar example here: http://www.igniteui.com/grid/sorting-remote
If you wish to manually build your query to the database you would need to manually handle all remote operation.
All remote operations add the related to the action information in the Query string. For example for the paging the page and pageSize options are added to the query string. For example a request for the first 10 items that should appear on page 0 would look like this:
http://<DataSourceURL>?page=0&pageSize=10
The “page” is the current page index you’re on and the pageSize is the number of records per page.
Similarly when you filter and additional “filter” option is added to the QueryString that contains the Key of the column , the condition and the value.
For example if you filter by a column with key “ProductID” and the condition is Equals and the set value is 9 the request would look like this:
http://<DataSourceURL>?filter(ProductID)=equals(9)&page=0&pageSize=10
You could get that on the server action and manually build your request to filter and get the data for the current page based on the Query string options that the grid sends.
For example if you need to get the filter for the “ProductID” column you can get it as follows:
string productIDFilter = this.Request.QueryString["filter(ProductID)"];
Based on it you can build filter your data and return it as a Json result to the grid.
I’ve attached an example when the ProductID column is filtered with the default Equals filter the data source is manually filtered and paged and the related result is returned from the DataSourceURL action in the controller.
Refer to the attached sample and let me know if you have any questions.
Best Regards,
Maya Kirova
Developer Support Engineer II
Infragistics, Inc.
http://www.infragistics.com/support
Thanks alot. This is what i was looking for.
One little thing, The querystring is in the form "filter(ColumnName)..." .
And for fetching the querystring parameter we have to write something like this:
string productIDFilter = this.Request.QueryString["filter(ProductID)"]; string NameFilter = this.Request.QueryString["filter(Name)"]; string priceFilter = this.Request.QueryString["filter(ListPrice)"]; string dateFilter = this.Request.QueryString["filter(ModifiedDate)"];
But my gird is generic & the autogenerate columns(true) is set , & the datasource is set at runtime therefore the grid displays data of different entities. I cannot explicitly write filter(columnName) because I dont know the column names. The grid will have numerous columns & will display data for different entities therefore different column names every time. What do you suppose I should be doing? Is there a way like this :
string[] Filter = this.Request.QueryString["filter"]; //An array of filters for different columns? Can this be done?
How can I fetch the querystring parameter of filter without knowing the column names?
----------------------------------------------
Also in my remote paging how can i tell the gird about hte total number of records in the database table so that it displays appropriate amount of page number at the bottom. I am using MVC Controller's action method to set the grid model like this:
gridModel.Features.Add(new GridPaging() { Type = OpType.Remote, Inherit = true, PageSize = 10 ,CurrentPageIndex=0,TotalRecordsCount=myCount });
But the grid does not display page numbers according to myCount. It displays page numbers with respect to the amount of data it received from the datasource, but as i told you earlier I am pulling only a single page from database using PageSize & Page therefore the data is only for one page, I want to tell the grid about the number of rows present in my grid through setting TotalRecordsCount=myCount but this is not working. There was a property named RecordCountKey which is set in the View(.cshtml) file but this property is not available in Action method of controller. How can I set the recordsCountKey in ActionMethod of controller? Is TotalRecordsCount & RecordsCountKey same thing? TotalRecordsCount is not working for me & RecordCountKey is not available as a property in action method of my controller.
-----------------------------------------------
Please guide. I am stuck here. Thanks alot for the last reply I have some idea about what to do now but if you could answer these queries that would be great.
****My query about fetching filter(ColumnName) when columnNames are not known is resolved. Though I had to do a lot of coding for it , If Infragistics provides a builtin way to do this then please tell me. ****
Please tell me about the Paging query that i posted in my above previous post regarding the RecordCountKey for MVC.GridModel.
As I mentioned there is a built-in way for the grid to handle all remote operations (remote sorting, filtering, paging etc.) by using the [DataSourceAction] attribute for the Action that returns the data. However it’s not compatible with your scenario since in that case it’s necessary to return the whole IQueryable data in the Action with the [DataSourceAction] attribute and let the Action Filter(DataSourceAction) handle the data filtering.
Regarding the paging.
The grid relies on a property in the response json that contains the total record count in order to calculate how many pages it should show.
The property it will look that value in is determined by the “recordCountKey” property.
This basically means that in your Json response you need to make sure there’s a property in the response that corresponds to what’s set for the RecordCountKey and contains the total record count.
For example in the sample I’ve previously attached:
features.Paging().PageSize(10).Type(OpType.Remote).RecordCountKey("TotalRecordsCount");
And for the Json Response a property with that name is added:
List<Products> currentData = list.Skip(currentPageIndex).Take(pageSize).ToList();
DataModel model = new DataModel() { Records = currentData, TotalRecordsCount = list.Count };
JsonResult result = new JsonResult();
result.Data = model;
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
You can refer to the attached sample and let me know if you have any questions regarding this.