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
I have a scenario that I want to check the record count before exporting the data. If the record count is beyond what I want to allow, then I would like to stop the process. I was hoping to do it in the WebGrid1_InitializePostBack because this is called anyway when you click the Export button. I would like to make one trip from the Client to the code behind. So I have this in the InitializePostBack ..
WebGrid1_InitializePostBack because this is called anyway when you click the Export button. I would like to make one trip from the Client to the code behind.
So I have this in the InitializePostBack ..
if (e.Action == PostBackAction.Export) { if (((DataView)e.DataSource).Count > 6000) { ISNet.WebUI.FunctionParameter[] prms = new ISNet.WebUI.FunctionParameter[1]; prms[0] = new ISNet.WebUI.FunctionParameter("dummy", "string"); e.Grid.ClientAction.InvokeScript("ExportIssues", prms); //[HERE I WANT TO STOP THE EXPORT PROCESS} } }
If you wish to retrieve the total row from filtered grid, you will need to get the count from the defaultview not the datatable. Here is the new snippet:
protected void WebGrid1_PrepareDataBinding(object sender, DataSourceEventArgs e){ rowTotal.Value = ((DataTable)WebGrid1.DataSource).DefaultView.Count.ToString();}
You will also need to update the hidden value after every filter using the InitialisePostback server side event handler:
protected void WebGrid1_InitializePostBack(object sender, PostbackEventArgs e){ if (e.Action == PostBackAction.ColumnFilter) { rowTotal.Value = ((DataTable)WebGrid1.DataSource).DefaultView.Count.ToString(); WebGrid1.ClientAction.RenderControl(rowTotal); }}
The solution for your required scenario, to cancel export if the record count is beyond allowed amount of exported records, can be achieved by using OnBeforeRequest client side event of WebGrid.
<script type="text/javascript"> <!-- function WebGrid1_OnBeforeRequest(controlId, action) { } --> </script> ... <ISWebGrid:WebGrid ID="WebGrid1" runat="server" DataSourceID="AccessDataSource1" Height="250px" UseDefaultStyle="True" Width="500px"> <LayoutSettings AllowExport="Yes" AllowFilter="Yes"> <ClientSideEvents OnBeforeRequest="WebGrid1_OnBeforeRequest" /> </LayoutSettings> ... </ISWebGrid:WebGrid>
First, we’ll need to determine from which actions the request was raised. If the request is raised from Export action, then check the record count and return false if the record is greater than, for example, 50 records.
function WebGrid1_OnBeforeRequest(controlId, action) { var WebGrid1 = ISGetObject(controlId); var rowsCount = WebGrid1.RootTable.GetRowsCount(); //check if request is raised from Export action or not if (action == "Export") { //cancel export if exported rows amount is greater than 50 rows if (rowsCount <= 50) return true; else { alert("Exported rows are greater than 50 rows."); return false; } } }
Hope this helps. Please let us know if you have different requirement.
Yudi,
I saw onBeforeRequest function the problem is we have Paging implemented and we have PagingSize=500 and PagingExportMode="ExportAllData" so they have the ability to export all data. The only way to get all rows would be in the code behind, so that's why I said InitializePostback.
I need more time to discuss this with WebGrid development team.
I’ll get back to you with the result of the discussion.
There is no way to abort export event from server side, so for your requirement we’ll need to cancel the export from client side.
Since the grid uses paging, then GetRowsCount() method will returns the value PagingSize property instead of exact total rows retrieved by WebGrid. The total rows retrieved by WebGrid can be obtained by using hidden field. Please add following tag into your page.
<input type="hidden" id="rowTotal" name="rowTotal" runat="server" value="0" />
The value of the rowTotal input object will be set during PrepareDataBinding server side event of WebGrid.
protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { rowTotal.Value = ((DataTable)WebGrid1.DataSource).Rows.Count.ToString(); }
Next, modify the OnBeforeRequest function so it becomes as follow.
function WebGrid1_OnBeforeRequest(controlId, action) { var WebGrid1 = ISGetObject(controlId); var rowsCount = document.getElementById("rowTotal").value; var maxExportRow = 50; //check if request is made from Export action or not if (action == "Export") { //cancel export if exported rows amount is greater than maxExportRow if (parseInt(rowsCount) <= maxExportRow) return true; else { alert("Exported rows are greater than 50 rows."); return false; } } }
This should do the trick. Please let us know whether this helps or not.
Yes and No.
This works if you don't have filtering turned on; however, we give the user the ability to filter their data. So, what is happening now is. say the max is 6000 records. I have returned data of 100,000 and then they filter column 1 and the total count is now 2000. The rowcount is still showing 100,000 NOT the 2000 from the filter. I have an aggregate count on column 1 if this helps. Is there a way to retreive aggregate count value client side?
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