Custom cell data in data table.

I have an attribute that is the full path of a file.

In the datatable I want just the file name (after the last ‘/’).

I can’t do this with a template string, so I tried with a template function, however I get all of the items in the table in the function. I was expecting to get an item for each row.

Hi,

Could you provide a snippet please ?

http://webix.com/snippet/000ba6f4

You can use function as a template

http://webix.com/snippet/66360bda

Hi Maria,

For me the object that is passed into the function for the template (obj, in your example) is an object representing the response from the “url” attribute.
Which contains all of the rows, and there is no way to get the object for the current row.

Can you share a snippet, or any other kind of demo where the issue can be checked?

http://webix.com/snippet/a1b1f54f

Please check the updated snippet

http://webix.com/snippet/13711d2e

data property must contain the array of data objects

That is the data that I get back from “url” How can I modify it?

In the ready function I am doing

this.data.clearAll();

and then adding items so it is an array of objects.

I’m not using the data attribute. I’m using the “url” attribute. That is what the data looks like.

In the ready function I am setting this.data to be an array of data objects.

But the value that gets passed to the template function is not a single object.

Any ideas?

I’m not using the data attribute. I’m using the “url” attribute. That is what the data looks like.

It doesn’t matter. The only difference between url and data that data is fetched by ajax call in the first case. All other data processing logic is the same for both.

When you are using url server side must return an array of object. That is default data format expected by component. if code returns something like { jobs:[ ]}, it will not be rendered correctly.

If you can’t change the syntax of server side code, try to use

view:"datatable",
data: webix.ajax("./some.php").then(function(data){ return data.json().jobs; })

Above logic will make ajax request to the server side script, will fetch data and will use data.jobs for rendering.

Thanks that works.

How would you set the request url dynamically? I’m using Jet and the url depends on a url parameter. I can’t seem to do

$$(“attemptsList”).data = webix.ajax($$(“attemptsTable”).url).then(function(data){ return data.json().attempts; });

You can do the same like next

var data = webix.ajax(someurl).then(function(data){ return data.json().attempts; });
$$("attemptsList").parse(data);

I can’t get that to work with a list.

I was able to get it to work if I passed parse an object with the data in the data property.

As far as promise resolves with a correct data object, both approaches must work correctly.

var data = webix.ajax("some")
//this works
list.parse(data);
//this works too
data.then((data) => list.parse(data));

It only worked if I passed an object to list.parse.

list.parse({data: data})