EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: stephenl on December 23, 2018, 06:27:21 AM



Title: Cellstyler for a subgrid
Post by: stephenl 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


Title: Re: Cellstyler for a subgrid
Post by: jarry 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'}
    ]],


Title: Re: Cellstyler for a subgrid
Post by: stephenl on December 24, 2018, 12:39:00 AM
Works Great !
Thank you !


Title: Re: Cellstyler for a subgrid
Post by: stephenl 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


Title: Re: Cellstyler for a subgrid
Post by: stephenl on December 24, 2018, 01:04:39 AM
Solved - just spotted parameter.....halign:centre !