0

I am adding record in grid using startEditingNew method as below.

var COLUMN_NAME = {

    name : "user_name",
    lastname : "user_surname",
    age : "user_age"
};


addDataToGrid : function (name, lastname, age){

MyGrid_Grid.startEditingNew({

       COLUMN_NAME.name: name,
       COLUMN_NAME.lastname: lastname,
       COLUMN_NAME.age: age
     });
}

But, my above function raise error and does not add record to grid. If I use "user_name" string instead of "COLUMN_NAME.name" , It works fine.

How can I use variable as column name??

Thanks in advance

Levi
  • 7,313
  • 2
  • 32
  • 44
extjs user
  • 263
  • 7
  • 17

1 Answers1

0

This is a javascript question, not a SmartClient one.

Anyway, if you need to use that approach, you may write something like:

addDataToGrid : function (name, lastname, age){
    var record = {};
    record[COLUMN_NAME.name] = name;
    record[COLUMN_NAME.lastname] = lastname;
    record[COLUMN_NAME.age] = age;
    MyGrid_Grid.startEditingNew(record);
}

see also Rules for unquoted JavaScript Object Literal Keys?

Community
  • 1
  • 1
claudiobosticco
  • 413
  • 2
  • 8