I have an igGrid with two columns, the 1st being a hidden column (key = "Name") which contains the row primary key, and the second just a simple string value. I have implemented custom delete row functionality via a javascript function which accesses the selected cell's row index as follows:
var cell = $("#gridTerms").igGridSelection("selectedCell");var rowIndex = cell.rowIndex;
This works as expected. I then need to extract the rowId (primary key) value of the row to be deleted, but since it is a hidden column, I can only access it via the underlying datasource as follows:
var ds = $("#gridTerms").igGrid("option", "dataSource");
then trying the following:
var rowId = ds.Records[rowIndex].Name; //the primary key column = "Name"
This doesn't work, as the row index I got from cell.rowIndex is relative to the current page being displayed, not the row index relative to it's position in the datasource, so it actually returns the incorrect rowId, so doing:
$("#gridTerms").igGridUpdating("deleteRow", rowId);
will delete the wrong row.
How do I get the correct rowIndex for the selected cell/row in the underlying datasource when paging is enabled?
Hello duster,
Thank you for sharing your experience with the community.
If I can provide further assistance regarding this matter, please let me know.
Regards,
Tsanna
So after more trial and error, this is the solution that worked:
var dataView = $('#gridTerms').data('igGrid').dataSource.dataView();var rowId = dataView[rowIndex].Name;
using dataView means you do not have to worry about page number and page size.
Hopefully this will help others who have the same issue.
I now determine the row index value for the selected cell/row in the underlying datasource as follows:
var pageIndex = $("#gridTerms").igGridPaging("pageIndex");
var pageSize = $("#gridTerms").igGridPaging("pageSize");
var dsRowIndex = rowIndex + (pageIndex * pageSize);
but trying to access the primary key rowid value in the datasource row as follows doesn't work:
var rowId = ds.Records[dsRowIndex].Name;
I have also tried
var rowId = ds[dsRowIndex].Name;
but that doesn't work either.