How to get row state?


#1

I want to know state of all rows in grid.

Added, updated or deleted


#2

I’m only aware of one way to get status of each row and that is using the ‘change’ event ( status: string - the status of the operation:“add”|“update”|“remove”):

grid.data.events.on(“Change”, function(id,status,updatedItem){
console.log(“An item is updated”);
});

Perhaps you could add a ‘status’ value to your data file that updates on each change so the row status is always available to you? Or, maybe DHX support has a better way?


#3

Hi :vulcan_salute:, this is only an observation. In the case you need this informatión in the browser DataCollection has an private property called _changes. This is for internal use, but maybe you can use it to get the state of the row… Be careful because I do not know if there are any side effects that could lead to unforeseen results. For example, when a save operation is successfully performed the order array is updated. A support member could dispel my doubts.

See this example and display the console to see the state of the _changes property.

We can do something like this:

function getRowState(data, id) {
    const changes = data._changes
    if(changes && changes.order){
        for(let i of changes.order){
            if(id === i.id){
                return i.status
            }
        }
    }
}

// Then call 
const state = getRowState(grid.data, 23)

I hope that it will help you