refer to a cell for a function in datatable

Hello,

I’m trying to do a charAt on a string contained in a cell and display it in another cell (for each rows in my large datatable)

Here is what I’ve tried:

function char(a,b){
    return a.charAt(b)
}

In my colum definition:

What I try to do

 {
   id: "deal",
   template: char("19FFSFNEUIT01", 2),
   header: [null, "Deal", {content: "selectFilter"}],
   width: 50,
   sort: "string"
  },

I’d like to replace 16FFSFNEUIT01 with the value contained in a cell in another colum? How do I refer to it?

I’ve tried this:

 {
   id: "deal",
   template: char("this.getItem("reference", 2),  //where reference is the id of the other colum
   header: [null, "Deal", {content: "selectFilter"}],
   width: 50,
   sort: "string"
  },

I’ve also tried to use the math method without any luck so far:

 {
   id: "deal",
   math: "char([$r, reference], 2)", //or "char([$r, :0], 2)"
   header: [null, "Deal", {content: "selectFilter"}],
   width: 50,
   sort: "string"
  },

What is the correct way to do it?

Thank you very much

try template as function

{
   template: function($row){
      return char($row.REF_COL, 2);
   }
}

Thank you integral :slight_smile:

It’s working!

I talked too fast :frowning:

It displays the value correctly but I cannot use the filter in the header (the option list is empty)

I would advise to use scheme->$change property of datatable: https://docs.webix.com/desktop__data_scheme.html

{
   scheme:{
      $change: function($row){
         $row.TARGET_COL = char($row.REF_COL, 2);
      }
   }
}

and use column TARGET_COL without template

Works perfectly this time, just had to adapt the function a bit because the add row button stopped working:

function char(a, b) {
    if(!a) return '';
    else return a.charAt(b);
}

And thanks for pointing me on the scheme part of the documentation, I think it will help me with other issues I have.