EasyUI Forum
June 26, 2024, 06:26:08 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: How can formatter the datagrid row value.  (Read 5881 times)
frankgao
Jr. Member
**
Posts: 53


View Profile Email
« on: February 05, 2016, 08:05:47 AM »

I want to format the quantity cell for dynamic.
like
1 row, the precision value is 2, When input the quantity=10,the quantity cell display 10.00
2 row, the precision value is 3, When input the quantity=11,the quantity cell display 11.00

Code:
columns: [[
                { field: 'peid', hidden: true, title: 'ID' },
                { field: 'code', title: 'Code', width: '110px', sortable: true },
                { field: 'name', title: 'Name', width: '120px', sortable: true },
                { field: 'model', title: 'Model', width: '140px', sortable: true },
                { field: 'precision', title: 'Precision', width: '70px' },
                {
                    field: 'qty', title: 'Quantity', width: '100px', editor: {
                        type: 'numberbox', options: {
                            required: true,
                            formatter: function (value, row, index) {
                                return parseFloat(value).toFixed(row.precision);
                            }
                        }
                    }
                },
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 07, 2016, 12:23:26 AM »

Please refer to the code below:
Code:
$('#dg').datagrid({
  onBeginEdit: function(index,row){
    var ed = $(this).datagrid('getEditor',{index:index,field:'listprice'});
    var opts = $(ed.target).numberbox('options');
    $.extend(opts, {
      formatter: function(value){
        return parseFloat(value).toFixed(row.precision);
      },
      parser: function(s){
        return parseFloat(s).toFixed(row.precision);
      }
    })
  }
})
« Last Edit: February 07, 2016, 06:28:34 AM by stworthy » 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!