iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi,
There are 100's of records in the grid, but we are loading first 50 records bydefault, when user clicks on "Load more data" icon from the grid taskbar, we are loading another set of 50 records.
If I click on "Load more data" icon from the grid taskbar 3 times, it load 200 records, now if I refresh the grid I want to retain the same no. of records (i.e., 200), but the InitializeDataSource event fires, and it load the first 50 records.
Kindly suggest the solution.
Thanks in advance
Apologize for the delay in sending this.
Please follow the step-by-step below in order to implement you required scenario.
<asp:HiddenField ID="HiddenField1" runat="server" />
function WebGrid1_OnBeforeRequest(controlId, action) { var WebGrid1 = ISGetObject(controlId); var hf = document.getElementById("HiddenField1"); if (action == "More") { if (hf.value != "") hf.value = parseInt(hf.value) + 10; else hf.value = WebGrid1.TotalLoadedRows + 10; } return true; }
protected void WebGrid1_InitializePostBack(object sender, PostbackEventArgs e) { if (HiddenField1.Value != "") { WebGrid1.LayoutSettings.VirtualPageSize = int.Parse(HiddenField1.Value); WebGrid1.VirtualLoadArgs.RequestedRows = int.Parse(HiddenField1.Value); } if (e.Action == "More") { WebGrid1.RebindDataSource(); ISNet.WebUI.FunctionParameter[] total = new ISNet.WebUI.FunctionParameter[1]; total[0] = new ISNet.WebUI.FunctionParameter(WebGrid1.VirtualLoadArgs.TotalDataSourceRows.ToString(), "string"); WebGrid1.ClientAction.InvokeScript("SetTotal", total); } else if (e.Action == "ColumnSort") { WebGrid1.RebindDataSource(); ISNet.WebUI.FunctionParameter[] total = new ISNet.WebUI.FunctionParameter[1]; total [0] = new ISNet.WebUI.FunctionParameter(WebGrid1.VirtualLoadArgs.TotalDataSourceRows.ToString(),"string"); WebGrid1.ClientAction.InvokeScript("SetTotal",total); } }
function WebGrid1_OnAfterResponseProcess(controlId, actionName, lastRequestObject, xmlResponseObject) { var WebGrid1 = ISGetObject(controlId); var hf = document.getElementById("HiddenField1"); var table = WebGrid1.RootTable; WebGrid1.TotalLoadedRows = hf.value; return true; }
function SetTotal(total) { var WebGrid1 = ISGetObject("WebGrid1"); var hf = document.getElementById("HiddenField1"); if (hf.value != "") WebGrid1.GetElement(WG40.STATUSBAR, WG40.HTMLROW).childNodes[3].innerText = "Loaded " + hf.value + " of " + total; }
A simple sample is enclosed as attachment. Please have the sample tested on your end and let us know whether this helps or not.
It is the default of WebGrid that when user clicks the “Refresh” button, WebGrid will invoke InitializeDataSource event and load the initial number of records.
In order to implement your scenario, I’d like to suggest you to utilize the OnBeforeRequest client-side event. OnBeforeRequest specifies the client-side function to be invoked when a request action to server is about to be made.
It has two parameters: controlId and action. The controlId is the ID of WebGrid that fires this client-side event and the action is the request action of WebGrid to the server.
When user loads more data, the value of action property is “More”; and when user clicks the refresh button, the value of action property is “Refresh”. A global variable is added to store the number of “More” action each time user loads more data. This variable is incremented every time user loads more data.
Next, invoke wgLoadMore method to load more data for n times (the n times is equal to the number of “More” action count). A delay – window.setTimeOut – needed to let WebGrid finish its request before starting a new request.
<script type="text/javascript"> <!-- var loadmore = 0; function WebGrid1_OnBeforeRequest(controlId, action) { var WebGrid1 = ISGetObject(controlId); if (action == "More") loadmore += 1; if (action == "Refresh") { for (var i = 0; i < loadmore; i++) { window.setTimeout(function () { wgLoadMore(controlId); }, 2000); } } return true; } --> </script>
Hope this helps.
Hi Yudi,
Thanks for the response.
1. First time it is working fine, but the next time it is populating the alert message saying that "Please wait while WebGrid is in progress processing request..."
2. After loading (retaining) all the record, I need to retain the selection of the item, so it should not be deselected.
3. How to pass value between WebGrid1_InitializeDataSource to WebGrid1_InitializeLayout event and vice versa.
My approach to retain the no. of loaded items and item selection is:
* Hold WebGrid1.VirtualLoadArgs.RequestedRows from WebGrid1_InitializeDataSource event when "Load More" action is performed
* Set the value to e.Layout.VirtualPageSize in WebGrid1_InitializeLayout event
So that the next time "Refresh" is called, that value will be set to VirtualPageSize hence it will load the same no. of records at once, instead of calling it multiple times.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname