JqGrid gridComplete: - getRowData - get the value of a row cell from an array

Syntax required to set variables from jqGrid getRowData Property

Quoting line by line - you just need to output the values ​​of the ID and Phrase columns to variables

gridComplete: function () { var allRowsInGrid = $('#list').jqGrid('getRowData'); for (i = 0; i < allRowsInGrid.length; i++) { pid = allRowsInGrid[i].ID; vPhrase = allRowsInGrid[i].Phrase; vHref = "<a href='#' onclick='openForm(" + pid + ", " + vPhrase + ")'>View</a>"; } }, 

It was easy to get the id using getDataID :-)

Need help getting specific column values ​​for pid and vPhrase for i

Greetings

+6
source share
2 answers

Try the following:

 var ids = jQuery("#list").jqGrid('getDataIDs'); for (var i = 0; i < ids.length; i++) { var rowId = ids[i]; var rowData = jQuery('#list').jqGrid ('getRowData', rowId); console.log(rowData.Phrase); console.log(rowId); } 

Please note: if your goal is to add a link to a cell that calls the javascript method, you can achieve this using formatter as follows, formatter should be added to colModel, as you add other column properties such as name, index, width, align, etc., so you can avoid iterating over the string data

 formatter: function(cellvalue, options, rowObject) { return "<a href='#' onclick='openForm(" + rowObject.ID + ", " + rowObject.Phrase + ")'>View</a>"; } 
+14
source

This is what I use when I want to get RowID data for specific Cell .

 var selRow = jQuery("#list10").jqGrid('getGridParam','selarrrow'); //get selected rows for(var i=0;i<selRow.length;i++) //iterate through array of selected rows { var ret = jQuery("#list10").jqGrid('getRowData',selRow[i]); //get the selected row name = ret.NAME; //get the data from selected row by column name add = ret.ADDRESS; cno = ret.CONTACTNUMBER alert(selRow[i] +' : ' + name +' : ' + add +' : ' + cno); } 
+4
source

All Articles