EasyUI Forum
March 29, 2024, 07:33:18 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 do I replace NaN with blank in easyui footer?  (Read 7872 times)
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« on: May 12, 2017, 08:20:49 PM »

I have a footer summary generated from php for datagrid. Instead of the real value (numeric value), I put   for the value but this returns NaN.
Please find the attachment.

Code:
array(
 'field1'=>' ',
 'field2'=>' '
);

How do I put the value in the server-side(php) in order to display blank space instead of NaN?
« Last Edit: May 12, 2017, 09:13:16 PM by dove » Logged
jarry
Administrator
Hero Member
*****
Posts: 2260


View Profile Email
« Reply #1 on: May 13, 2017, 12:31:20 AM »

Please call 'reloadFooter' method to update the footer row. If you define a 'formatter' function to convert string to number, please allow it to return a empty string.
Code:
$('#dg').datagrid('reloadFooter',[
{field1: '', field2: ''}
]);
Logged
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« Reply #2 on: May 13, 2017, 10:26:36 AM »

How do I define the formatter for this, I run your code under the onLoadSuccess, it does not work.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2260


View Profile Email
« Reply #3 on: May 13, 2017, 04:53:21 PM »

Please show an example to demonstrate your issue.
Logged
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« Reply #4 on: May 14, 2017, 02:08:15 AM »

Here is the code I am using:

Code:
<table class="easyui-datagrid" id="stockdg"
        data-options="
                url:'getinventory.php',
                rowNumbers:'true',
                pagination:'true'                               ,
                pageSize:20,   
                showFooter:'true',
                fitColumns:'true',                                                   
                onLoadSuccess:function(){
                        $(this).datagrid('reloadFooter',[
                            {clAvgPrice: '', clAmount: ''}//This does not return black but returns NaN
                        ]);
                }">
        <thead>
            <tr>
                <th field="drugName" width="auto" sortable="true" align="left">Drugs</th>
                <th field="unit" width="auto" sortable="true" align="center">Unit</th>
                <th field="opQnt" formatter="formatAny" width="auto" sortable="true" align="right">Op.Qty</th>
                <th field="opCost" formatter="formatAny" width="auto" sortable="true" align="right">Avg.Price</th>
                <th field="opAmt" formatter="formatAny" width="auto" sortable="true" align="right">Op.Amt</th>
                <th field="prQnt" formatter="formatAny" width="auto" sortable="true" align="right">Purc.</th>
                <th field="prCost" formatter="formatAny" width="auto" sortable="true" align="right">Avg.Price</th>
                <th field="prAmt" formatter="formatAny" width="auto" sortable="true" align="right">Purc.Amt</th>
                <th field="qntOrdered" formatter="formatAny" width="auto" sortable="true" align="rightr">Sale</th>
                <th field="slPrice" formatter="formatAny" width="auto" sortable="true" align="right">Avg.Price</th>
                <th field="slAmt" formatter="formatAny" width="auto" sortable="true" align="right">Sale&nbsp;Amt</th>
                <th field="closeAmount" formatter="formatAny" width="auto" sortable="true" align="right">Clt.Qty</th>
                <th field="clAvgPrice" formatter="formatAny" width="auto" sortable="true" align="right">Avg.Price</th>
                <th field="clAmount" formatter="formatAny" width="auto" sortable="true" align="right">Cl.Amt</th>
            </tr>
        </thead>
    </table>
    <script>
        function formatAny(val,row){
            if(val){
                return parseFloat(val).toFixed(2);
            }else{
                return '0.00';
            }
        }
    </script>

getinventory.php returns the following JSON:

   
Code:
JSON=
            '{
            "total":2,
            "rows":[{
                        "drugName":"Speed",
                        "unit":"Bottle",
                        "opQnt":"500.00",
                        "opCost":"50.000000",
                        "opAmt":"25000.000000",
                        "prQnt":"0.00",
                        "prCost":"0.000000",
                        "prAmt":"0.000000",
                        "qntOrdered":"2.00",
                        "slPrice":"80.000000",
                        "slAmt":"160.000000",
                        "closeAmount":"498.00",
                        "clAvgPrice":"43.33333333333334",
                        "clAmount":"21580.00000000000000"
                        },{
                        "drugName":"Shark",
                        "unit":"Bottle",
                        "opQnt":"100.00",
                        "opCost":"50.000000",
                        "opAmt":"5000.000000",
                        "prQnt":"0.00",
                        "prCost":"0.000000",
                        "prAmt":"0.000000",
                        "qntOrdered":"5.00",
                        "slPrice":"80.000000",
                        "slAmt":"720.000000",
                        "closeAmount":"95.00",
                        "clAvgPrice":"43.33333333333334",
                        "clAmount":"4116.66666666666700"
                    }],
            "footer":[{
                        "drugName":"Total",
                        "opQnt":"600.00",
                        "opCost":"100.000000",
                        "opAmt":"30000.000000",
                        "prQnt":"0.00",
                        "prCost":"0.000000",
                        "prAmt":"0.000000",
                        "qntOrdered":"7.00",
                        "slPrice":"160.000000",
                        "slAmt":"880.000000",
                        "closeAmount":"593.00",
                        "clAvgPrice":"&nbsp;",
                        "clAmount":"&nbsp;"
                    }]
            }';
Logged
jarry
Administrator
Hero Member
*****
Posts: 2260


View Profile Email
« Reply #5 on: May 14, 2017, 05:07:31 PM »

Your 'formatAny' function should be:
Code:
function formatAny(val,row){
if(val){
var v = parseFloat(val);
return isNaN(v) ? '' : v.toFixed(2);
}else{
return '';
}
}
Logged
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« Reply #6 on: May 17, 2017, 03:31:56 AM »

This works like a charm. Thank you very much.
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!