EasyUI Forum
September 19, 2025, 09:39:02 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Datagrid: add class to cells ?  (Read 12245 times)
Ellipsis
Full Member
***
Posts: 113


View Profile WWW
« on: November 15, 2012, 09:13:37 AM »

Is it possible to add classes to datagrid cells and/or columns?
Logged
Ellipsis
Full Member
***
Posts: 113


View Profile WWW
« Reply #1 on: January 16, 2013, 01:31:20 AM »

Not possible?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 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'
});
Logged
Ellipsis
Full Member
***
Posts: 113


View Profile WWW
« Reply #3 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){....}

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!