How to get the object which represents the selecte

2019-06-11 08:07发布

问题:

I have a webpage with a slickgrid which renders an array of objects on a grid. I want to do some dynamic stuff (a master-detail like setup) when the selected row changes. However to be able to do this, I would need the data of the selected row. I know that the grid.getCurrentCellNode() function will give me the dom element of the current node, but what I am looking for is a javascript object. For instance, if I use an array of objects like the one below

data = [ 
        {id:1, name:'Khaja', dob:'26/07/1985'},
        {id:2, name:'Iqbal', dob:'26/07/1935'}
        ......
        ...
        ];

and if my selected row is the row with id equal to 2, I want to be able to retrive the object {id:2, name:'Iqbal', dob:'26/07/1935'} Is there a way through which I can get this object?

回答1:

You can use the onSelectedRowsChanged event and the getSelectedRows method.



回答2:

data[i]={
    ID: json[i].ID,
    Name: json[i].Name,
    Description: json[i].Description,
    CreatedDate: myDate,
    makesub: "---",
    shared: json[i].IsShared
    };
.....

grid.onClick = function (e, row, cell) {
            if (columns[cell].id == "colname"){ 
                        // where colname is the column on which you want to trigger the click
            alert("clicked:"+row+", albumID:"+data[row].ID);