Author Topic: Problem when set and get cell content with different way  (Read 4580 times)

noctrona

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
Problem when set and get cell content with different way
« on: March 03, 2014, 02:19:06 pm »
Hi,

I met a strange problem.
Please have a look with the following code:

Code: [Select]
/* part a */
var DM = $("#grid_json").pqGrid("option", "dataModel");
var data = DM.data;
data[rowIndex][colIndex] = 'test';
alert(data[rowIndex][colIndex]);

/* part b */
var DM = $("#grid_json").pqGrid("option", "dataModel");
var data = DM.data;
data[rowIndex]['Name'] = 'test';
alert(data[rowIndex]['Name']);

/* part c */
var DM = $("#grid_json").pqGrid("option", "dataModel");
var data = DM.data;
data[rowIndex][colIndex] = 'test';
alert(data[rowIndex]['Name']);

As the above codes, I have a cell the dataIndex is "Name". If I set value for this cell and get it value by same way, I can get the cell content (like part a&b).
But if I use different way to set and get value. (part c) I can only get an "undefined" value.

Did I have any mistakes for this operation?


Thank you!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Problem when set and get cell content with different way
« Reply #1 on: March 03, 2014, 09:21:48 pm »
Please refer to API documentation. data is a javascript array of arrays (for array data) and an array of objects (for JSON data).

data[rowIndx][dataIndx] is the right way to get and set cell data.

colIndx has a special meaning; it means index of column in colModel array.

noctrona

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
Re: Problem when set and get cell content with different way
« Reply #2 on: March 04, 2014, 08:27:41 am »
Please refer to API documentation. data is a javascript array of arrays (for array data) and an array of objects (for JSON data).

data[rowIndx][dataIndx] is the right way to get and set cell data.

colIndx has a special meaning; it means index of column in colModel array.

Thanks for your answer. :)