I'm trying to use the "rowById" function on a grid (with paging) with a primary key. If the Id that I am looking for is on the "current" page it finds it fine. But if it is on not on the current page it is not found. Is there a way to use "rowById" if I don't know which page the Id will be found on? I want to find the row and get the index from it so I can programmatically move to the correct page and then select that row by index and save the index off. The code I am using is simple - but doesn't work if the Id is on a different page than the current one.
var row = $(gridId).igGrid("rowById", 123);if (row) indexToSelect = row.index();
Hello Ryan,
Please note that with Paging enabled, only certain number of records as specified by the pageSize properly is rendered to the user. You can get specific record from the datasource, but you can't get its DOM element if it's not rendered yet.
If you want to know the correct page index where specific record is placed, you may find this record by primary key in the datasource and see its index which you should divide by the pageSize. The result will be the correct page index.
If I can provide you with further assistance, please let me know.
Regards,Tsanna
Yes I had tried this approach previously by using
var record = $(gridId).igGrid("findRecordByKey", rowToSelect.keyValue);
That returns me the row in the datasource properly, but I can't see any "index" there - am I missing it? Once I find the record in the datasource, how do I know what index it is in the datasource?
If I can provide you with further assistance regarding this matter, please let me know.
Yes I can access that and I had tried it previously. It only returns the data for the current page however. I believe the way we are filling the grid, we are not actually passing back the data for all pages from the server, just the current page + number of records. Because of this I don't think there is a way to do what I want to do. So I have moved on at this point - I don't think what I am trying is possible with the way we are doing the remote paging.
You may get the igDataSource instance and call some of its API methods to access your data, for instance $("grid").data("igGrid").dataSource._data. Please let me know if this works for you.
$("#grid").data("igGrid").options.dataSource gives me a URL that is used to return the data source from the server. Is there something else that can give me the datasource, because what you sent is not giving me an array of the records.
Hi Ryan,
By finding the record in the dataSource I meant you access the grid dataSource using for example the following code: $("#grid").data("igGrid").options.dataSource. This will return you an array of all records in your dataSource and you can find the desired record and its index. Does this help you achieving your purpose?