Skip to main content

How to reload server-side data in a dojo.table

3 replies [Last post]
kjambor
Offline
Joined: 2004-04-19

Hi,

On my form, I have a dojo.table which loads its data from data1.jsp service. The page loads fine and I see all the data. Now, I added a button to reload the data in the table from the server using doAjax() call:

function button7_onClick() {
jmaki.doAjax({ url : "rows.jsp",
method : 'POST',
callback: function(_req) {
var rows = _req.responseText;
jmaki.getWidget('table1').clear();
jmaki.log("Rows: " + rows); // observed that rows have correct JSON format
jmaki.getWidget('table1').addRows({value : rows});
}});
}

I get following warning in jmaki console after my dojo.table gets cleared:

table1 : Warning. Attempt to add record to dojo.table. with duplicate row id: undefined. Autogenerating new id.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alcmontejo
Offline
Joined: 2007-10-15

jmaki.log("Rows: " + rowsJSONText ); //[b] observed that rows have correct JSON format[/b]

sample:

[
{ id : 'i1', title : 'Book Title 1', author : 'Author 1', description : 'A look at the samples ', url : 'https://ajax.dev.java.net/samples'},
{ id : 'i2', title : 'Book Title 2', author : 'Author 2', description : 'A Some long description', url : 'https://ajax.dev.java.net/samples'},
{ id : 'i3', title : 'Book Title 3', author : 'Author 3', description : 'A Some long description', url : 'https://ajax.dev.java.net/samples'},
{ id : 'i4', title : 'Book Title 4', author : 'Author 4', description : 'A Some long description', url : 'https://ajax.dev.java.net/samples'},
{ id : 'i5', title : 'Book Title 5', author : 'Author 5', description : 'A Some long description', url : 'https://ajax.dev.java.net/samples'}
]

Thanks, Allen

rasane
Offline
Joined: 2007-08-15

does the following callback make sense?

callback: function(_req) {
var rowsJSONText = _req.responseText;
var objRows = eval('(' +rowsJSONText + ')');
jmaki.publish("/dojo/table/clear", { });
jmaki.log("Rows: " + rowsJSONText ); // observed that rows have correct JSON format

jmaki.publish("/dojo/table/addRow", {value : objRows });
}

hopefully that works, i haven't run it yet, but i have similar code structure working

regards,
rasane

Message was edited by: rasane

kjambor
Offline
Joined: 2004-04-19

Hi Rasane,

Yes your suggestion worked. I was missing the eval() thinking I can just feed the json string response to table widget.

Regards,

-- Kamyar