Home > database >  Get Value of another Column in Datatables.net
Get Value of another Column in Datatables.net

Time:09-07

I am using datatables.net in my Code and I have a scenario where I need to pass value of some other column in render function of another column in a javascript as parameter. I have tried with row.columnname but I am getting undefined when trying to view the value.

Below is my code. Any help on this will be very useful.

Inside Ajax under columns section while binding datatables.net with my data

columns :[ {"data":"test1"} {"data":"test2"} { "data" :"test3" ,"render":function(data,row) { return xyz(row.test1, row.test2) //calling another javascript function with other 2 column values. Also getting row.test1 and row.test2 as undefined. Need proper value of test1 and test2 } }]

Thanks

CodePudding user response:

I have tried with row.columnname but I am getting undefined when trying to view the value.

Try to changne row.test1 into row['test1']

CodePudding user response:

I think you were nearly there. The render function provides 4 arguments (data, type, row, meta) - what happens if you try this:

  ...
  columns: [
    {
      "data": "test1"
    }, {
      "data": "test2"
    }, {
      "data" :"test3",
      "render": function(_ ,_, row) {
        return xyz(row.test1, row.test2)
      }
    }
  ],
  ...

Perhaps try and work up a JSFiddle or something to illustrate what you've got, we'd be better placed to help if we can see what you're seeing.

  • Related