jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Refresh virtual grid from database
Tagged: #jqwidgets-grid, grid, javascript grid, jquery grid
This topic contains 3 replies, has 2 voices, and was last updated by Hristo 8 years, 1 month ago.
-
Author
-
Hi, I just want to share something I found out the hard way, and get some confirmation that now I am doing it right.
I have a grid with paging in virtual mode, that I want to refresh every 15 seconds to show changes from the server.
function UpdateGrid() { $('#jqxgrid').jqxGrid({ source: dataAdapter }); // dataAdapter.dataBind(); $('#jqxgrid').jqxGrid("updatebounddata", "cells"); }
The call to updatebounddata results in a call with the correct string jsonData, containing the pageSize and current pageNum.
As you can see I first had the dataBind(). However, when using that, there is an extra round trip to the controller (Asp.Net Core).
The call to dataAdapter.dataBind() results in a server call with jsonData == “{}”.
This had the side effect that the data of the first page was shown, even when the user had moved to another page, as pageNum defaults to 0.Without the dataAdapter.dataBind() this is working fine. In fact, after initializing the grid I call updateGrid(), and never use dataAdapter.dataBind(). dataAdapter has autoBind: false
Anything you would recommend to change here?
PieterHello Pieter,
Yes, this is a right approach that you present. Also, it is possible to use and only “updatebounddata” to update the Grid.
Hint: I would like only to mention you should be careful with a case when doing some another operation (as filtering or sorting) and update the Grid in every 15 seconds.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comThanks Hristo,
what is the issue with filtering and sorting with 15s updates? I have not seen any issues, the json data for filtering and sorting is passed to the server. I query the full set on the server, and then use filtering and sorting to get the set used for the grid display, as found in the example.I just made the following change to your example, rather than looping through the set, I let Linq do it, but I assume that wont make a big change
count = allItems.Count; List<T> items = new List<T>(); int startpageindex = pageNum * pageSize; int pagecount = (startpageindex + pageSize <= count) ? pageSize : count - startpageindex; items = allItems.GetRange(startpageindex, pagecount); return items;
But I am curious about your warning on the update with other operations.
Hello Pieter,
I am missing this information that ‘data for filtering and sorting is passed to the server’.
Let me know if I could help you with something else.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.