Updating the data source

flights = [
{id:1,from:“Moscow”,to:“Bangkok”,type:0,price:230,details:“best price”,available:10},
{id:2,from:“Oslo”,to:“Cape Town”,type:0,price:489,details:“best price”,available:25},
{id:3,from:“Viena”,to:“Dubai”,type:0,price:225,details:"",available:5}
]

I have used the data source similar to the one above for the grid.
Now when I add a row in the grid, I also want to add it in the above data source along with the id. How can I do that ? What is the best possible way ?
Kindly reply.
Thank you.

Not quite sure, why do you need the separate array of objects?
The grid preserves all data inside as it was provided and has api to get data objects by id. ( grid.item(id) )

Also, you can get the full content of grid’s data as

var data = grid.serialize(); //returns an array of objects

Actually My problem is there is an auto increment unique column in the database named “ID” which is not displayed while showing the grid.
But that ID field is present in the json string. Hence the row can be accessed by that ID for modifying and deleting.

However when a new entry is added, the new ID assigned to it in the database should also be linked with the new row in the grid. Bcoz if I have to modify or delete that new added row (Which wont be present in the json string), I will have to send the ID to identify that row uniquely in the database.

I have written the code for getting that ID from the server after the new row is added in the table in database. But I want to add that either in datastore or json string which I have.
So that when I write
var itemId = $$(“grid”).getSelected();
The appropriate ID which corresponds to the one in database gets retrieved. So how should I proceed ?

Please help. This is causing me a lot of problems.
Thank you.

In short, how to change the id of the new added row without selecting the row ? That is user should not know id has been changed.

If you are using dataProcessor - id updating executed automatically ( temporary ID is replaced with new id from database, after data saving )

If you are using custom code, you can use

grid.data.changeId(oldid, newid);

It will work for any data-based component.

Thanks a lot. It worked.

var itemId = $$(“grid”).getSelected();

With this method i can get the Id of the selected Row in a grid View. Is there a possibility to iterate through the column values for that row. I’d wasted more than a day for searching regarding this but no luck :cry: ,

Please help regarding the same

Thanks
Shaounak

var selRow = $$(“grid”).item(id); //where id is the id of the selected row.
for ( var i = 1; i < no of columns; i++) {
selRow[colheaders[i]] or selRow[//id of the column]
}

Try this out.