1

How to get table first row data in jqgrid?

enter image description here

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> 
sathya
  • 1,404
  • 2
  • 15
  • 26

3 Answers3

2

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

Runcorn
  • 5,144
  • 5
  • 34
  • 52
1

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'];
Mitul Maheshwari
  • 2,647
  • 4
  • 24
  • 38
1

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);
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
  • are you calling this after $("#gridtable2").jqGrid(.. call? are there any errors on console? Can you share jsfiddl of it so that i can help you better way. Also I forgot to define name_c variable in my post. please update it and try again. – Bhushan Kawadkar Jul 09 '14 at 07:24
  • Refer this link http://stackoverflow.com/questions/24603337/how-to-load-data-in-jqgrid-manually and after table load then if add some more data I want previous record in table so I want to do this task.. – sathya Jul 09 '14 at 07:26