Hi,
I am trying to get the selected row index from iggrid with different pages in jquery.
When I have only single page then I am able to get value. But when i have multiple pages in grid then i am not able to get the records/values/index.
var grid = $(iggridid).igGrid("selectedRows");
Scenario1:
I have selected 2 rows from page1 and page2. I get correct index value for page2 but I am getting -1 for page1.
Scenario2:
When i have single page then below code works fine
grid[0].element.context.rows[j].cells[1].inntertext;
Please help to get value or index of selected rows from iggrid with different pages.
Thanks
Mukesh
Hello Mukesh,
Thank you for posting in our community.
The behavior that you are experiencing is expected. By design, when Paging is enabled the index correspond to the current visible index of the row. Since rows from pages, that are currently not in the view area do not have actual visible index their index is set to -1. If you would like to uniquely identify the rows and get reference to their cell values you can use the getCellValue ot getCellText methods. For example:
var selectedRows = $("#grid").igGrid("selectedRows"),
firstSelectedRowID = selectedRows[0].id,
cellValue = $("#grid").igGrid("getCellValue", 3, "col_key");
Additionally, please keep in mind if you select rows across different pages and Row Selectors feature is not enable you have to hit Ctrl key while you are making the selection to ensure that previously selected rows are not dissected.
Please test my suggestion on your side and let me know if you need any further assistance with this matter.
Hi Vasya,
I have tried your samples as mentioned above.
The syntax firstSelectedRowID = selectedRows[0].id returns 10 digit value
how to consume it to get row value
selectedRows[0].id returns the primary key of your grid set via the primaryKey property. Depending on what you set for this option is what is going to be returned. Alternatively, if the primary key is not set to any particular column an auto generated id is created and this might be the reason why you are getting a 10 digit number returned. Please ensure that the primary key is set to a column of your choice and let me know if you need any further assistance with this matter.
As much as i know igGrid maintains only 0-9 row index value even for different pages in grid. This makes harder to get the selected rows when we want to select from different page.
What I want is I have igGrid with multiple pages and I will selected rows from different pages. I want the row index for those selected rows index value.
Kindly provide the source code for this. I have tried this for a week and getting delayed.
Please reply as soon as possible.
Index is a number illustrating the visible row index. It could be more than 9 depending on how many rows are displayed on the page. When the row is not on the current page, respectively it is not visible, its index is -1.
That is why my suggestion is to use rows primary key in order to uniquely identify them.
$("#getSelRowsCategories").click(function(){ var selectedRows = $("#grid").igGrid("selectedRows"); if(selectedRows.length === 0) { alert("There are no rows selected."); } else{ $(selectedRows).each(function(index){ alert("Selected row id:" + selectedRows[index].id + " has category:" + $("#grid").igGrid("getCellValue", selectedRows[index].id, "CategoryName")); }); } });
Attached you will find a working sample illustrating my idea for your reference. You can select multiple rows across pages (make sure when selecting rows on different pages that you hold the CTRL key. Otherwise all previously selected rows will be dissected) and afterwards when you click the "Get Categories for selected rows" button you will get an alert with all selected rows categories.
Please have a look at this sample and let me know if you need any further assistance with this matter.
6281.igGridSelectionAcrossPages.zip
Thanks Vasya,
This is what i wanted but i need it on checkbox checked items and that too multiple.
Can you help me please. If we can call it through event then fine like check box checked etc.
Currently what happening is when i select multiple checkbox and by clicking other cells the selected items got cleared.
I am glad that you found my suggestion helpful.
Can you please provide me more details regarding your requirement? Are you looking for event that is fired when a new row is getting selected, or for event fired after a new row is selected? Any details relevant to your scenario are going to be highly appreciated and helpful.
In regards to the selection with checkbox getting cleared when you click on cell in the grid I have already answered in the forum thread that you created for this issue.
Please let me know if I can be of any further assistance.