EasyUI Forum
April 18, 2024, 07:00:31 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: Cellstyler for a subgrid  (Read 4416 times)
stephenl
Newbie
*
Posts: 30


View Profile
« on: December 23, 2018, 06:27:21 AM »

Hello

I am trying to apply a format, to the cell of a sub grid.

The format should add a comma to seperate thousands, and also change the text to RED if the value is less than 0.

Suggestions would be appreciated

Thank you
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: December 23, 2018, 06:19:34 PM »

Define a 'formatter' function on the column, change its colour on some conditions. Please refer to this code:
Code:
onExpandRow: function(index,row){
  var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
  ddv.datagrid({
    url:'datagrid22_getdetail.php?itemid='+row.itemid,
    fitColumns:true,
    singleSelect:true,
    rownumbers:true,
    loadMsg:'',
    height:'auto',
    columns:[[
      {field:'orderid',title:'Order ID',width:200},
      {field:'quantity',title:'Quantity',width:100,align:'right',
        formatter(value){
          if (value<0){
            return '<span style="color:red">'+value+'</span>'
          } else {
            return value;
          }
        }
      },
      {field:'unitprice',title:'Unit Price',width:100,align:'right'}
    ]],
Logged
stephenl
Newbie
*
Posts: 30


View Profile
« Reply #2 on: December 24, 2018, 12:39:00 AM »

Works Great !
Thank you !
Logged
stephenl
Newbie
*
Posts: 30


View Profile
« Reply #3 on: December 24, 2018, 12:52:25 AM »

Hello

I now need to align the column values to the right, but would like to leave the column header aligned to the centre..

I have tried adding align:right to the formatter however this seems to be ignored ??
 
columns:[[
      {field:'orderid',title:'Order ID',width:200},
      {field:'quantity',title:'Quantity',width:100,align:'center',
        formatter(value){
          if (value<0){
            return '<span style="color:red;align:right">'+value+'</span>'
          } else {
            return '<span style="align:right">'+value+'</span>'
          }
        }
      },

Any suggestions ?
Thank you
Logged
stephenl
Newbie
*
Posts: 30


View Profile
« Reply #4 on: December 24, 2018, 01:04:39 AM »

Solved - just spotted parameter.....halign:centre !
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!