How do you rebind the data when a search button is clicked?
I setup the grid as follows:
@( Html.Infragistics().Grid<MVCMobile1.EF_Result>() .ID("Grid1") .AutoGenerateColumns(true) .Columns(column => { column.For(x => x.EntryDate).DataType("date").HeaderText("Entry Date"); }) .DataSourceUrl(Url.Action("SPList")) .Width("90%") .Height("750px") .DataBind() .Render())
I found a solution by not using the Helper function to create the grid but to recreate the grid in jquery every time the search button is clicked. I'm not sure if that is the correct way of doing it. Is there a way to send data to the grid that was created using the helper function?
In the jquery code I am calling:
$(
'#Grid1').igGrid({ dataSource: '/Home/SPList/', ...
Hello,
It really is going to depend on how you want your search to work as to what would be the best approach to take. My recommendation is to send the info from the search back to your controller and let that modify the data that is returned by ActionResult for the DataSourceUrl.
I've attached a sample that demonstrates this approach. In my sample I set up the page and have a button that will commit a post operation. In the HttpPost ActionResult I extract the text from my search field and store that information in Session. Then, in my GridDataSourceAction I check to see if this is set and either return all the data or a subset.
Please let me know if you have any questions or concerns about this approach.
Thanks. Your example does a form post. I am trying to do this on the client. I can just recreate the grid inside the jquery click function but I thought there may be a way to just hook up the new data to the grid instead of recreating the grid.
Hi,
assuming you've got the data on the client, you can do the following
function onClick ( e) {
$("#gridID").igGrid("option", "dataSource", yourDataArray);
}
It should set a new data source, and cause rebinding. Even though this could lead to some unexpected results in the context of MVC, because if you are using remote functionality for features (such as in paging/sorting/filtering) , triggering the respective action will cause an AJAX request, therefore your state may change . Also if you have remote paging, and set a data source & rebind locally, you would lose track of the page management.
hope it helps. Thanks,
Angel