Title: How do I replace NaN with blank in easyui footer?
Post by: Alfred 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. array( 'field1'=>' ', 'field2'=>' ' ); How do I put the value in the server-side(php) in order to display blank space instead of NaN?
Title: Re: How do I replace NaN with blank in easyui footer?
Post by: jarry 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. $('#dg').datagrid('reloadFooter',[ {field1: '', field2: ''} ]);
Title: Re: How do I replace NaN with blank in easyui footer?
Post by: Alfred 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.
Title: Re: How do I replace NaN with blank in easyui footer?
Post by: jarry on May 13, 2017, 04:53:21 PM
Please show an example to demonstrate your issue.
Title: Re: How do I replace NaN with blank in easyui footer?
Post by: Alfred on May 14, 2017, 02:08:15 AM
Here is the code I am using: <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 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: 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":" ", "clAmount":" " }] }';
Title: Re: How do I replace NaN with blank in easyui footer?
Post by: jarry on May 14, 2017, 05:07:31 PM
Your 'formatAny' function should be: function formatAny(val,row){ if(val){ var v = parseFloat(val); return isNaN(v) ? '' : v.toFixed(2); }else{ return ''; } }
Title: Re: How do I replace NaN with blank in easyui footer?
Post by: Alfred on May 17, 2017, 03:31:56 AM
This works like a charm. Thank you very much.
|