ListGrid - Total Column and Submit

I’ve create a listgrid for use in a Tabset (included via a external JS file).

I’m after creating a simple test application, which totals up the number of buildings and total number of bedrooms.

I searched the docs for a total column function but couldn’t find one could anyone point me in the right direction. At the moment the following will put a total in the right hand column if you edit a cell, click a different row, click back to the edited row and click a different row again.

var lastRecord = false;

countryData = [{property:"Semi",bedrooms1:"5",bedrooms2:"4",total:"9"}, 
{property:"Flat",bedrooms1:"3",bedrooms2:"5",total:"8"}, 
{property:"House",bedrooms1:"4",bedrooms2:"7",total:"11"}, 
{property:"Shed",bedrooms1:"1",bedrooms2:"0",total:"1"}, 
{property:"Total",bedrooms1:"13",bedrooms2:"16",total:"29"}];

VLayout.create({ID:"grid1",width:"100%", height:"100%",members: [
			ListGrid.create({
			ID: "countryList",
			width:500, height:224, alternateRecordStyles:true,
			showAllRecords:true,
			data: countryData,
			fields:[{name: "property", title: "Property", type:"text", canEdit: true}, 
{name: "bedrooms1", title: "Bedrooms 1", type:"integer", canEdit: true}, 
{name: "bedrooms2", title: "Bedrooms 2", type:"integer", canEdit: true}, 
{name: "total", title: "Total", type:"integer", canEdit: true}],
			
		    cellClick: function (record, rowNum, colNum) {
		    	if (lastRecord) {
					var newtotal = (lastRecord.bedrooms1*1)+(lastRecord.bedrooms2*1);
					if (newtotal != lastRecord.total) {
						lastRecord.total = newtotal;
						grid1.markForRedraw();
					}
				}
		    	lastRecord = record;
		    },
			cellContextClick: "this.sayCellEvent('Context-clicked', record, colNum); return false;"
			
			
			, autoFetchData: true
			, canEdit: true
			, editEvent: "click"
			, editByCell: true
			})]})

I have looked at cubegrid but it seems far to complex, to be honest I couldn’t get my head round it. Does it require the SC server package as well?

When it comes to submitting the listGrid to the server, how do I go about doing this? Ideally I would like the full grid to be editable and have a save button below - which would save all the changes at once.

I’ve managed to get the dynamic forms to save the data to the server but can’t get my head round how to do this for the listgrid.

Thanks for reading.

You can use the field.changed() event to update your totals column. Note that refreshCell is a good way to do a more selective refresh.

autoSaveEdits:false will cause edits to be queued for later manual saving via calling saveAllEdits().

As long as you are using DataSources, grids save identically to forms - they submit “update” or “add” operations to their DataSource. If a DynamicForm can save to a given DataSource, then so can a ListGrid with no further code.

Thank you I almost have something that works now.

At the moment the listGrid does an update every time a cell is changed, this results in far to many request and therefore the grid becomes slow.

What I would like is no updates to be done on cell/row change but only do an update when the user clicks a button, ‘Save All Changes’.

DataSource.create({
ID: "countryDataDS"
//---(fields and operationBindings)---//
});
VLayout.create({ID:"grid1",width:"100%", height:"100%",
members: [
ListGrid.create({
ID: "countryList",
width:500, height:224, alternateRecordStyles:true,
showAllRecords:true,
dataSource:countryDataDS
, autoSaveEdits:false
, autoFetchData: true
, editEvent: "click"
, canEdit: true
, editByCell: true
})]});

What changes need to be made to do this?

Thanks again.

Hi nickc,

The code you have provided in fact defers all saving if placed into eg this example and modified so that it uses “worldDS” (which is loaded by that example).

How are you deciding that saves are occurring?

Note also: setting showAllRecords:true effectively disables on load on demand.

I’m running firebug so I can check all the requests a page makes.

My code makes a request each time a cell is edited.

However when using the same code in your example for the build listgrid and using your DS, no requests are made.

I then replaced all you code in your demo with mine and changed the URL so it requested the XML from my site, again no requests were made.

I removed autoSaveEdits:false and requests were made on each edit.

There is one difference though.

When using my code with in your demo the request when an edit is made looks like this:

data=<data xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:type="xsd:Object"><url>?do=update</url><httpMethod>GET</httpMethod><params xsi:type="xsd:Object"><property>Shed</property><bedrooms1 si:type="xsd:long">111</bedrooms1></params><requestBody></requestBody></data>&_transaction=<transaction xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:type="xsd:Object"><transactionNum xsi:type="xsd:long">23</transactionNum><operations xsi:type="xsd:List"><elem>__ISC_NULL__</elem></operations></transaction>&protocolVersion=1.0

But when using my code locally:

POST:property=House&bedrooms1=111
PARAMS:do update

Apart from that I can find no difference between when the code is run locally and when in your demo.

How my DS is setup to request, used both locally and in your demo.

, dataFormat:"xml"
, recordXPath:"//house"
, operationBindings:[
{operationType:"fetch",
dataURL:"smartclient.php?do=fetch"
}, //--- etc for update add remove ---//

Thanks hope that helps to find a solution.

Version: SmartClient_60_LGPL.zip (03/01/2008).

The difference in the posted data is expected. One is the format for contacting the ISC server and one is what a RestDataSource posts for integration with PHP and other technologies.

If you can post your server’s exact response, that will make this a runnable test case that we can take a look at.

I am sure the problem is client side, not server side. Since when I ran the same SC code in your demo system and contacted my server it worked correctly it’s only when run locally it failed.

Server response to SC fetch request:

<List>
<house>
<property>Semi</property>
<bedrooms1>5</bedrooms1>
<bedrooms2>4</bedrooms2>
<total>9</total>
</house>
<house>
<property>Flat</property>
<bedrooms1>3</bedrooms1>
<bedrooms2>5</bedrooms2>
<total>8</total>
</house>
</List>

Server response to SC update request:

<List>
<house>
<property>Semi</property>
<bedrooms1>x111</bedrooms1>
<bedrooms2>4</bedrooms2>
<total>9</total>
</house>
</List>

Is there any special parameters that the SC demo system defines?

Do you need any more details? Or is it not fixable?

Hi NickC,

You still haven’t posted DataSource fields, which is required to make your example runnable. Ideally, package up your example as an Issue Report as indicated in the Debugging topic.

However, judging by the server’s response, the problem is almost certainly that there is no primary key field in the DataSource (or in the data), which is required for data that can be updated by the user. SmartClient needs a unique id to tell the server what record is being updated, and requires the corresponding unique id returned in cache update data.

I have uploaded a test case here:
http://download.yousendit.com/79BD09D37200D604

Details:
fails.zip (1 KB)

If you extract all 4 files in to the folder below isomorphic.

The relative path should be:

<script type=“text/javascript” src=“isomorphic/system/modules/ISC_Core.js”></script>

Everytime you make a change to the grid the data is submitted, this should not happen.

In this example the row “Shack” will have “Bedrooms 1” updated to 500 everytime a change is made.

Primary Keys are being used.

Hi Nick
Thanks for the test case - we were able to reproduce the problem and figure out what was going on.
You’re correct - it is a client-side bug in the 6.0 LGPL build which is causing saveAllEdits to be ignored in some cases.
You can work around the problem by adding an explicit saveByCell:false to your ListGrid definition.

The underlying bug has been fixed internally (which explains the difference in behavior on our website examples), and the fix will be present in our next public release, SmartClient 6.1.

Sorry for the confusion - please let us know if the workaround of setting saveByCell doesn’t resolve the issue for you

Thanks
Isomorphic Software

Thank you savebycell works.

Now when the user makes a change no requests are made to the server.

I have a button with the function saveAllEdits(), this sends a individual request for each row which has been edited.

Is there any way to make this one request for multiple rows?

IButton.create({title:"Save Changes", click:"nonreslist.saveAllEdits()"})

Hi NickC,

Saving as a batch is an automatic behavior when using saveAllEdits() with the SmartClient Server and server-side data integration.

Otherwise, you need to invent some format to send multiple update to the server and create some server to parse that. Various editValues APIs on the ListGrid will let you detect which records and fields have been edited.