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
Hello
We have a simple WebGrid (currently using version 6) that displays some rows from the database (unbound) where the user can edit one column and add/remove additional rows with a button. The changed data does not go into the database until the user confirms he wants to save everything together or maybe cancels out.
The WebGrid is defined with AllowAutoDataCaching="false", because caching does not work with our web farm setup.
The WebGrid has a DataKeyField defined and some columns, all read-only, except one for the Weight with AggregateFunction="Sum", DataFormatString="#0.00", DataType="System.Double", EditType="TextBox".
The grid_InitializeDataSource function dynamically creates the rows based on a class variable and assigns the created DataTable to e.DataSource. The content of the class variable is filled in Page_Load.
Because WebGrid fails to update the Sum on hitting Enter, we have a ClientSideEvent OnExitEditMode defined. There we calculate the current total and update it with grid.RootTable.GetElement(WG40.COLFOOTER,WG40.HTMLTABLE).rows[1].cells[...].innerText=...
(Adding/Deleting rows works by the user clicking a button and in the event adding a row to grid.DataSource and calling grid.RebindDataSource. Not relevant to the problem.)
Now the problem is that after every value edit and selection change afterwards, the InitializeDataSource event gets called again, overwriting the edited user values and the total calculation also gets wrong (the screen still shows the user values though). I think this happened after our move to the web farm and disabling the caching mentioned earlier.
What is the proposed way to do this without caching data within the grid?
Eric
Hi Handy,
Ok, thanks. In the meantime (I needed a solution) we replaced the WebGrid with the standard grid from Microsoft ASP.NET. This works fine. So problem solved for now.
Hello Eric,
I am also using a data table and AllowAutoDataCaching false. The footer works well and gets updating. I wonder why it does not in yours. However, for your issue perhaps, your calculate function is not configured properly. I am not sure that you need RebindDataSource too. If the value is not updated to your database and you try to rebind datasource, of course it will show incorrect value. It will read the value of your current value in database.
Please try to see my simple sample. If you can, please try to replicate the issue in a simple runable sample and send it back to me. I will try to see which part that we missed.
Regards,Handy
Thanks for your reply. But your sample seems to have the same issues (if not more).
Please see the attached code, based on your sample.
I've added a Save button and a js. The js is actually not needed to show the problem, but it solves another issue: If you edit a cell (enter 4.0 for example) and press the Enter key, then the footer Sum will not get updated. This js fixes this issue.
Also I see that the Sum in the footer disappears as soon as you click on another cell in a different row. My real life code doesn't have this issue (only this sample), so fixing this here is not important.
Now for the Save button: We only want to do the save of all data (manually with a SP call) if the Sum of all values is 10.0, so we have to check this in the Save event handler. But if you step through there, you can see that there is no data available to save in this event handler. The data doesn't get cached - that's the problem I have. What is the recommended way to keep the data until a save? Probably in Viewstate somehow? Remember I that I can't allow AutoDataCaching.
Thanks, Eric
Hello,
Weird, at my end, my footer is getting updated. However, if you want to recalculate it manually and sent the changes to server without cache, this is not possible to do. Cache is needed for this scenario. However, you can have other workaround. e.g Use HiddenField control. You would need also to set FlyPostBackSettings PostInputControls="True" on WebGrid.
Hi,
We don't need to discuss the footer, even if there is a bug there. Maybe you're just not using WebGrid6 or you selected another row instead of just pressing Enter or whatever. The footer is not the problem.
FlyPostBackSettings are set to true for all four attributes already (maybe not in the sample though).
What we need is a grid that
- displays database data
- The user can change values in one column, in several different rows before it gets saved.
- Buttons (outside of the WebGrid) to add a new row (requires postback to server to get all data to get added to the new grid row, also requires a popup to select what to get added) But leave this requirement away for now.
- When the user presses a Save button there should be a postback to the server and there all changes get stored in the database at once.
Problem right now: When changing a row, there is a postback to the server which causes the InitializeDataSource event, re-reading the database and overwriting all previously changed data in the grid. How should this get solved?
I think I have to implement the UpdateRow event and store the changed data in the ViewState or something like that. What is the recommended way to implement something like that?
Best way would be to avoid a postback to server until the user presses the Save button, but I'm not sure if that's possible. Other controls (like textboxes) maintain their content in the ViewState even during a postback, but this doesn't work for the WebGrid data when AutoDataCaching is off.
Haven't I told you the answer in my previous post? It is not possible to do it without cache. However, there is a workaround. You need to store those information in hidden field.
In your previous post you were talking only about the footer, which is not the relevant issue. If you meant something else, then I didn't get that.
So you say that there is a workaround by using a hidden field. How would that work (except setting PostInputControls to true)? Can you adjust the latest sample to get this working?
I could not modify your sample because I don't know much about what kind of save or code that you wanted to call.
if(Sum==10.0) { //do save here //How do we get the data in the grid??? } else { //cannot save, Sum must be 10. }
So, basically how to save data is something that you need to take care of. I can only show how to get data in grid.E.g I added a hidden field to your sample, named sum.
function Table_ExitEditMode(controlId, tblName, editObject) { var cell = editObject.cellElement; var inp = editObject.element; var col = wgGetColumnByElement(cell); var row = wgGetRowByElement(cell); var sum = document.getElementById("HiddenField1"); switch (col.Name) { case 'Weight': if (IsValidPercentage(inp.value)) { var grid = ISGetObject(controlId); var grandTotal = 0; for (var i = 0; i < grid.TotalRows; i++) { // Note: The unary '+' is to convert the string into a number. if (i == row.Position) grandTotal += +inp.value; else grandTotal += +grid.RootTable.GetRow(i).GetCells()[col.Position].Value; } // column footer var NumInvisibleColumns = GetNumInvisibleColumns(grid); grid.RootTable.GetElement(WG40.COLFOOTER, WG40.HTMLTABLE).rows[1].cells[col.Position - NumInvisibleColumns+1].innerText = grandTotal.toFixed(2); } else { // not a valid percentage alert('\'' + inp.value + '\' is not a valid percentage!'); inp.value = cell.OldText; } break; } sum.value = grandTotal; return true; }
After you use PostInputControls to true, you should be able get the data in postback/server.In your idButton_OnClick, you should able to access the value by using hidden field id.
Thanks for your reply. Maybe you misunderstood me. I don't want to do anything with the Sum or the Footer. So I don't need to put the sum into any hidden field. The sum is just to block saving as long as the total is not 100%. We don't need to bother with that right now.
I want each individual value of the rows. So if someone edits five rows, I need these five values in the postback. If I understood you correctly, I should dynamically create hidden fields for every editable field. If the grid has two editable columns and a content of 6 rows, I would need to create 12 hidden fields. Then in ExitEditMode js event store the edited field by assigning the value in the correct field and in the postback read out all hidden fields, find the right ones and do the save that way. Is it that what you meant?
If yes, then I would still need to avoid postback after editing and changing the row selection to avoid that the values get overwritten after the postback. How would you do that?
Yes, you were correct. Instead by using HiddenField, you can also use SendCustomRequest() and AddInput() via script to send data to server. You can access it the data in InitializePostBack server side event. Actually, it would be too much effort if you disable the cache. In WebGrid 7, it has new feature called Batch Update. All the changes would not be saved until we accept all the changes. Event though we already used accept changes, we still can interrupt it in OnBatchUpdate server side event.All the changes in cells can be seen in changes collection. This feature can work well without caches.
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