Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Add record in listGrid using variable

    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

    #2
    Hi,

    question is not related to smartclient at all, javascript object literals cannot have variable names.

    you can only achieve this with [] as in this example:
    Code:
    var record = {};
    record[COLUMN_NAME.name] = name;
    record[COLUMN_NAME.lastname] = lastname;
    record[COLUMN_NAME.age] = age;
    MyGrid_Grid.startEditingNew(record);
    Hope it helps

    Comment

    Working...
    X