Working on optimizing an MVC application that uses SlickGrid for grid edits. The grid can vary from 500 to 25,000 rows with around 40 columns. While the grid functions well, I'm facing challenges when it comes to posting changed data to my controller for updating a SQL-side table.
The issues arise due to POST limits in MVC, despite tweaking the maxAllowedLengths in web.config and trying various approaches. It's clear that simply increasing data posting capabilities may not be the most efficient solution.
Let me share some pseudo-code illustrating my current data saving process:
function Save(data)
{
var changedData = [];
for(i = 0; i < data.length, i++) {
if(data[i].isChanged == 1)
{
changedData.push(data[i]);
//This array only includes properties/columns that are altered, totaling around 30.
}
}
if (changedData.length < 5000)
{
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(changedData),
success: success
});
} else
{
//Divide changedData into chunks of 5000 and iterate through AJAX calls.
}
}
I am exploring another approach for saving changes by queuing them up, sending to the controller, and executing sequentially server-side.
var pendingChanges = [];
function Save(data)
{
//Would prefer a one-go solution instead of chunking out changes.
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(pendingChanges),
success: success
});
}
grid.OnCellChange(....)
{
//Update cell data
pendingChanges.push(ID:item.id, Property:xxx,Value:item.value,TimeStamp:now);
}
function massCellChange()
{
var changedRows = [];
for (i = 0; i < data.length; i++;)
{
if (slickGridDataViewContainsThisItem)
{
changedRows.push(data[i].ID);
//Update slickgrid
}
}
pendingChanges.push(ID:[changedRows],Property:xxx,Value:item.value,TimeStamp:now);
}
On the controller end, once reaching the method, no issues are faced. I utilize JavaScriptSerializer or JSONConvert to parse the changeset into my model.
Exploring alternative patterns for handling large changesets is also welcome. Users can modify the entire grid at once, albeit limited to visible rows in the dataView, potentially leading to significant changes per user. Considering sending the global command as a single pending change, but yet to find an elegant way to POST which visible rows were modified during that action. (Setting ID property as an array has hit POST limitations.)
Appreciate any guidance!