Reputation: 1424
How to get table first row data in jqgrid?
Here I want 2 and 4.0 data from jqgrid how to get this value without click table value?
var rowId = $("#gridtable2").getRowData(0);
var name = rowId['m_tab_p'];
Here gridtable2 is jqgrid id, and m_tab_p is 1st column id..
JSP grid code:
<s:url id="remoteurl2" action="add_act" />
<sjg:grid caption="RECORDS" gridModel="dto_plot_rep" width="250"
height="70" href="%{remoteurl2}" id="gridtable2" rownumbers="true"
viewrecords="true" pager="true" pagerPosition="centar"
navigator="true" navigatorSearch="true"
navigatorSearchOptions="{multipleSearch:true}"
navigatorDelete="false" navigatorEdit="false" loadonce="true"
onCompleteTopics="cal_tot" userDataOnFooter="true"
rowNum="0">
<sjg:gridColumn name="m_tab_p" index="m_tab_plotno"
title="PLOT" width="180" align="left" search="true"
searchoptions="{sopt:['eq','cn']}" sortable="true" />
<sjg:gridColumn name="m_tab_c" index="m_tab_cent" title="CENT"
width="180" align="left" search="true"
searchoptions="{sopt:['eq','cn']}" sortable="true" />
</sjg:grid>
Upvotes: 1
Views: 7251
Reputation: 5224
To get the data of first row you can use following in loadComplete
//Call On JqGrid Load Complete
loadComplete:function(data){
//id list value
var ids = $("#gridtable2").jqGrid('getDataIDs');
//get first id
var cl = ids[0];
var rowData = $(this).getRowData(cl);
var temp= rowData['UserId']
},
And if you are using it outside of loadComplete use :
var ids = $("#gridtable2").jqGrid('getDataIDs');
//get first id
var cl = ids[0];
//fetch row data
var rowData = $("#gridtable2").getRowData(cl);
//fetch individual cell value
var celValue = $("#gridtable2").jqGrid ('getCell', cl, 'UserId');
And here is the working JSFIDDLE
Upvotes: 2
Reputation: 28513
Try this : you want to read only first row hence rowId =1. get row object and read each column value by its name.
var rowObj = $("#gridtable2").getRowData(1);
var name_p = rowObj['m_tab_p'];
var name_c = rowObj['m_tab_c'];
alert(name_p);
alert(name_c);
Upvotes: 1
Reputation: 2647
You can have data of raw in the rowData
> var rowId =$("#gridtable2").jqGrid('getGridParam','selrow');
> var rowData = jQuery("#gridtable2").getRowData(rowId);
you can also get particulate column value by this code
var colData = rowData['UserId'];
Upvotes: 1