How do I use the explicit variable instead of the column's name

159 views Asked by At
  onContentReady: function(e) {

    if (!e.component.detayColumnAdded) {
      e.component.detayColumnAdded = true;
      e.component.addColumn({
        cellTemplate: function(cellElement, args) {
          //$("<a>").text("Detay").on("click", function () {
          $('<a/>').addClass('dx-link')
            .text('Detay')
            .on('dxclick', function(info) {
              var dataGrid = $('#mygrid').dxDataGrid('instance');
              $.each(dataGrid.getSelectedRowsData(), function() {
                var usd = "USD BAKİYE"
                console.log(this.usd); // BUT UNDEFİNED.
              });
            }).appendTo(cellElement)
        }
      });
    }

  },

I am collecting information from the column according to the data coming from ajax. The ajax tell me how to get information according to usd balance. But this is not always the same. Get information from TL balance column.. So I defined the variable usd. This variable is equal to the name of the column. Then I wrote this.Usd undefined in the console. How do I solve this problem. How i will make it dynamic. Can you give a suggestion?

1

There are 1 answers

2
Jai On BEST ANSWER

Instead use the [] notation when you are using variable names to get the key of the object:

console.log(this[usd]); // here

Another option will be to pass the param in the callback function of the jQuery.each():

$.each(dataGrid.getSelectedRowsData(), function(i, obj) {
    var usd = "USD BAKİYE"
    console.log(obj[usd]); // BUT bracket notation still required.
});