EasyUI Forum
May 18, 2024, 04:51:37 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Is there a Cell styler function?  (Read 10861 times)
swells808
Newbie
*
Posts: 15


View Profile
« on: September 28, 2014, 05:23:33 PM »

So I have figured out how to use row styler for an entire row but what if I want to color just a cell on conditional content?

For example my columns are date, cycle, destination, depart, and arrive. I want to set the condition that if the date is greater than 09/01/2013 i only want the cell of the dates to appear green how do I do this without styling the entire row?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: September 28, 2014, 06:13:36 PM »

Please see this example http://www.jeasyui.com/demo/main/index.php?plugin=DataGrid&theme=default&dir=ltr&pitem=DataGrid%20Cell%20Style
Logged
swells808
Newbie
*
Posts: 15


View Profile
« Reply #2 on: September 28, 2014, 06:31:57 PM »

Thank you thats very helpful. The only question I have from here is what if I want to apply this style to only a specific column?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: September 28, 2014, 07:03:37 PM »

To set cell style for a column, please apply the 'styler' function to that column.
Code:
<th data-options="field:'listprice',width:80,align:'right',
        styler: function cellStyler(value,row,index){
            if (value < 30){
                return 'background-color:#ffee00;color:red;';
            }
        }
">List Price</th>
Logged
swells808
Newbie
*
Posts: 15


View Profile
« Reply #4 on: October 02, 2014, 02:52:52 PM »

Thank you for your help. The next step for me is how do I setup multiple conditions. So for example in a cell if the value is > yellow or > 5 turn red?
Logged
Pierre
Sr. Member
****
Posts: 439


View Profile Email
« Reply #5 on: October 08, 2014, 09:53:30 AM »

stworthy posted nice example, you need only to add your conditions, like
if (condition)
{
  return '...
}
else
{
  return 'something else
}
Logged
swells808
Newbie
*
Posts: 15


View Profile
« Reply #6 on: October 08, 2014, 02:05:27 PM »

Yes and you've all been so helpful thanks. The final formula that is working perfect in case anyone needs it is
Code:
styler:function cellStyler(value,row,index){
var v = parseInt(row.nxtsvc);
if (v > 5 && v <= 10){
return 'background-color:yellow;color:red;';
} else if (v > 10){
return 'background-color:red;color:yellow;'
} else {
//...
}
}
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!