Author Topic: getdata from grid  (Read 7979 times)

ncpowerbrute66

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 8
    • View Profile
getdata from grid
« on: November 23, 2015, 12:35:20 pm »
I can load grids fine using c# mvc but when I use the calls to getData, getRowData etc... I can't get an array as the documentation suggests. I create my grids like this:

        var colModel = [
        {
            title: "Name", //title of column.
            width: 65, //initial width of column
            editable: false,
            dataType: "string", //data type of column
            dataIndx: "REP_NAME" //should match one of the keys in row data.
        }

        var dataModelTop = {
            location: "remote",
            sorting: "local",
            sortIndx: "CHARGE_TYPE_DESC",
            sortDir: "up",
            dataType: "JSON",
            method: "GET",
            getUrl: function () {
                return { url: Url4controller };
            },
            getData: function (response) {
                return { data: response };
            }


        }

var grid_Top = pq.grid("#grid_Top", objTop);
var totalRecordsTop = $("#grid_Top").pqGrid('option', 'dataModel.data').length;  //this works

//I want to access the first row of a column named Name of a refreshed grid to populate eleswhere on my webpage
var datafrmgrid = $("#grid_Top").pqGrid( "getCell", { rowIndx: 0, dataIndx: "Name" } );  //does not work.

Please help




paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: getdata from grid
« Reply #1 on: November 23, 2015, 03:08:51 pm »
getRowData is the method to get data for a row.

Code: [Select]
var rowData =  $("#grid_Top").pqGrid( "getRowData", { rowIndx: 0 } );

Further to get cell value of field with dataIndx: "REP_NAME"

Code: [Select]
var cellData = rowData.REP_NAME
« Last Edit: November 23, 2015, 03:12:18 pm by paramquery »

ncpowerbrute66

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: getdata from grid
« Reply #2 on: November 23, 2015, 06:53:50 pm »
That makes sense.  I see where I was using the column name Name and not the dataIndex: REP_NAME.  But when I add the below lines I still can't access the value of a cell.

var repname = $("#grid_Top").pqGrid("getCell", { rowIndx: 0, dataIndx: "REP_NAME" });
 alert("rename="+repname); // this gives me an alert box message  repname=[object Object]
               
 var rowData = $("#grid_Top").pqGrid("getRowData", { rowIndx: 0 });
 var cellData = rowData.REP_NAME;
 alert("cellData=", cellData);   //this gives me an alert box message cellData=

I have attached my cshtml file.


ncpowerbrute66

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: getdata from grid
« Reply #3 on: November 23, 2015, 07:46:36 pm »
I got it to work.   Thanks for your help

//SOLUTION
var row1Data = $("#grid_Top").pqGrid("getRowData", { rowIndx: 0 });
var repname = row1Data.REP_NAME;
$("#reptop").text(repname);