how to get jqgrid first row data with out select in jsp?
Asked Answered
C

3

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> 
Clinician answered 9/7, 2014 at 6:53 Comment(0)
I
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

Impression answered 9/7, 2014 at 7:4 Comment(3)
which value is returning null? Check the updated answer.Impression
Now you can check yourself the fiddle, P.S yes it was returning null.Impression
Thank u so much runcornClinician
G
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'];
Golub answered 9/7, 2014 at 7:0 Comment(3)
it's inbuilt keyword of jqgrid. which will give you selected row idGolub
But I cannot select table's row.I want to get 1st row onlyClinician
1st row datas I want. that is row id is 0.Your code 1st line rowId returns null 2nd row has errorClinician
B
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);
Broom answered 9/7, 2014 at 7:10 Comment(2)
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.Broom
Refer this link #24603837 and after table load then if add some more data I want previous record in table so I want to do this task..Clinician

© 2022 - 2024 — McMap. All rights reserved.