EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Ellipsis on November 15, 2012, 09:13:37 AM



Title: Datagrid: add class to cells ?
Post by: Ellipsis on November 15, 2012, 09:13:37 AM
Is it possible to add classes to datagrid cells and/or columns?


Title: Re: Datagrid: add class to cells ?
Post by: Ellipsis on January 16, 2013, 01:31:20 AM
Not possible?


Title: Re: Datagrid: add class to cells ?
Post by: stworthy on January 16, 2013, 06:03:27 PM
An alternate solution is to use 'styler' and 'formatter' functions to change column style and its displaying data. Here is the extended method to allow you to add custom class to specified field.
Code:
$.extend($.fn.datagrid.methods, {
addCellClass: function(jq, param){
return jq.each(function(){
var p = $(this).datagrid('getPanel');
p.find('td[field="'+param.field+'"] div.datagrid-cell').addClass(param.class);
});
}
});

Usage example:
Code:
$('#dg').datagrid('addCellClass',{
  field: 'name',
  class: 'myclass'
});


Title: Re: Datagrid: add class to cells ?
Post by: Ellipsis on January 16, 2013, 10:20:55 PM
Thank you for the extension!
I like to keep the styling separate from the content, the conditional styling / format is handy though.
I suppose this is not possible with the class extension?
(Add à class depending in certain condition, ... Class: function(value,index){....}