How do I fetch data from Grid in Smartclient?

900 Views Asked by At

How do get the underlying data from a row click on a grid?

My code looks like this :

isc.ListGrid.create({
    ID: "countryList",
    width:1500, height:224, alternateRecordStyles:true,
    data: sampleData,
    fields:[
        {name:"id", title:"Id"},
        {name:"name", title:"Name"},
        {name:"version", title:"Version"},
        {name:"release", title:"Release"},
    ],

    canReorderFields: true,
    click: function (x) {
        alert('hi there' + x)
    }
})

If I add a click function, the alert pops up.

If put in a paramater 'x', and that seems to have some kind of value, but i can't decipher it means. What I really want is the underlying JSON data (see below) which is being passed in as sampleData.

{
id:"10621",
name:"PimsPacket020",
version:"0.1",
release:"undefined",},
{
id:"10621",
name:"PimsPacket020",
version:"0.1",
release:"undefined",
}
3

There are 3 best solutions below

0
On

I haven't been using Smartclient for quite some time, but, I think a better selection event for a grid row would be:

selectionChanged: "someFunction(this.getSelection())"

The this.getSelection() function will return an array of records even for a single selection.

For more information I suggest using the Smartclient on-line documentation( Smartclient 9.1 Documentation) and feature explorer(Smartclient Feature Explorer) together. This code work on earlier versions; from 8.x at least.

I hope this helps.

0
On

if your list contains chexbox (selectionAppearance: "checkbox") you have to use this.getSelection() that contain all selected items.  or you make a function with record parameter:

click: function (record) {
  isc.say ("ID:" + record.id + "Name:" + record.Name); 
}
0
On

Use this function to retrieve your record

recordClick: function (viewer, record, recordNum, field, fieldNum, value, rawValue) {
alert('hi there' + record.name);
}

For more information, please refer smartclient documentation http://www.smartclient.com/docs/8.2/a/b/c/go.html#method..ListGrid.recordClick