formatter.htm 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title></title>
  5. <link href="../../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet"
  6. type="text/css" />
  7. <script src="../../../lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
  8. <script src="../../../lib/ligerUI/js/core/base.js" type="text/javascript"></script>
  9. <script src="../../../lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
  10. <script src="../ProductData.js" type="text/javascript"></script>
  11. <script type="text/javascript">
  12. //扩展currency类型的格式化函数
  13. $.ligerDefaults.Grid.formatters['currency'] = function (num, column) {
  14. //num 当前的值
  15. //column 列信息
  16. if (!num) return "$0.00";
  17. num = num.toString().replace(/\$|\,/g, '');
  18. if (isNaN(num))
  19. num = "0.00";
  20. sign = (num == (num = Math.abs(num)));
  21. num = Math.floor(num * 100 + 0.50000000001);
  22. cents = num % 100;
  23. num = Math.floor(num / 100).toString();
  24. if (cents < 10)
  25. cents = "0" + cents;
  26. for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
  27. num = num.substring(0, num.length - (4 * i + 3)) + ',' +
  28. num.substring(num.length - (4 * i + 3));
  29. return "$" + (((sign) ? '' : '-') + '' + num + '.' + cents);
  30. };
  31. $(function ()
  32. {
  33. $("#maingrid").ligerGrid({
  34. columns: [
  35. {display: '产品', columns:
  36. [
  37. { display: '主键', name: 'ProductID', type: 'int'},
  38. { display: '产品名', name: 'ProductName', align: 'left', width: 100 },
  39. { display: '单价', name: 'UnitPrice', align: 'right' ,type:'currency' }
  40. ]
  41. },
  42. { display: '仓库数量', name: 'UnitsInStock', align: 'right', type: 'float'}
  43. ], data: ProductData
  44. });
  45. });
  46. </script>
  47. </head>
  48. <body>
  49. <div id="maingrid">
  50. </div>
  51. <div style="display: none;">
  52. </div>
  53. </body>
  54. </html>