Search code examples
jqueryobjectslickgrid

How to display an object property in a slickgrid?


I would like to display a document list with JQuery and SlickGrid. In my grid, I would like to display the owner's fullname. I can retrieve it with the property "owner" of an object "document" : document.owner.fullname.

I can display simple properties from a document (for example the title : document.title). But how to display object as property ?

The following source code show how I do (and doesn't works...) :

var columns = [
    {id:"title", name:"Title", field:"title"},
    {id:"owner.fullname", name:"Owner", field:"owner.fullname"},
];

My grid contains :
+-------------------------+
|Title           | Owner    |
+-------------+-----------+
|doc's title   |               |
+-------------+-----------+


Solution

  • As you use not a simple property of data entity, you should use a custom formatter. Something like this:

    var columns = [
       { id:"title", name:"Title", field:"title"},
       { id:"owner", 
         name:"Owner", 
         field:"owner", 
         formatter: function(row, cell, value, columnDef, dataContext){ 
           return dataContext.owner.fullName; 
         }
       }
    ];