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.
Yes I have done the same thing.. I have set RecordCountKey("recordCountKey"), this recordCountKey is a part of my model which contains the count of records in the database. That part is covered and working i was telling you about some other thing. The functionality works and the correct page numbers are rendered only after i change the page size from the builtin drop down menu of igGrid. But for the first time i see only one page. I was asking about this,
When testing this on my side with the previously attached sample I’m not able to reproduce the behavior you have described.
I’ve attached a screenshot of how this looks on the initial load for your reference.
Please test the project on your PC; whether or not it works correctly may help indicate the nature of this problem.
If the project does not work correctly, this indicates either a problem possibly specific to your environment, or a difference in the DLL versions we are using. My test was performed using version 14.1.20141.2031 of 14.1.
If the project does show the product feature working correctly, this indicates a possible problem in the code of your application. It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.
Or, if this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.
Please let me know if I can provide any further assistance.
Hello Maya,
Thanks for your time and cooperation. I was able to resolve the issue , In my grid I had a DataSource property which got an IQueryable of 10 records when the grid is loaded first time. & Because it was an IQueryable i couldnt supply the RecorCountKey property to the grid, Therefore the grid didnt display correct number of pages the first time, Only when the DataSourceUrl was hit through changing the pageSize, The grid got its RecordCountKey property through the Json result because DataSourceUrl returns ActionResult of type 'JsonResult' which contains Records as well as RecordCountKey where as the IQueryable<myModel> returned by DataSource only contained Records.
Solution:
I changed autogeneratecolumn to false, removed DataSource property from my grid model altogether, And only called DataSourceUrl after I add columns to my grid model & now the grid shows correct number of pages as soon as it is rendered.
The issue is resolved , I was just curious to know whether we could supply the RecordCountKey property in the DataSource(IQueryable) also or is it not possible? Though, my grid is working alright now, Thanks for your time and valuable help, Both my Filtering & Paging issues are resolved, Thanks.
I’m just following up to see if you’ve been able to resolve your issue. If you have any questions or concerns or if you need further assistance please let me know.
Developer Support Engineer
Yes, my issue was resolved, thanks for your help.