找回密码
 立即注册

QQ登录

只需一步,快速开始

醉汀雨笙

金牌服务用户

21

主题

93

帖子

336

积分

金牌服务用户

积分
336

微信认证勋章

醉汀雨笙
金牌服务用户   /  发表于:2020-9-23 15:41  /   查看:2954  /  回复:3
1金币
1.問題 使用wijmo grid 給表格賦值,其中有一個字段本身的小數位數是5位的,但是綁定到grid 後,自動只顯示兩位小數點。在你們的官網測試,也是只顯示兩位小數點,如何要數據顯示本身正常的小數位數,其中別的字段使用到該字段計算的問題,導致結果相差甚遠。
a.在實例中測試:添加小數位




b.編輯結束後,點擊鼠標結束編輯還是兩位小數

附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册

3 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-9-23 17:37:15
沙发
您好,默认情况下,显示的数据小数位为2,这个可以在columns的设置中进行修改,如图:
图中,n后边的数字就是希望保留的位数。
而实际上,这只是作为格式化来处理的,不会影响cell的真实值。
计算行为引用的是cell的真实数据,如果您的计算结果不正确,请检查其他的原因。

如果实在想显示真实位数,请参考这篇示例:
https://demo.grapecity.com.cn/wi ... ionalStyling/purejs

把app.js改为:
  1. import 'bootstrap.css';
  2. import '@grapecity/wijmo.styles/wijmo.css';
  3. import './styles.css';
  4. import { Globalize } from '@grapecity/wijmo';
  5. import { FlexGrid, Row, AllowMerging } from '@grapecity/wijmo.grid';
  6. document.readyState === 'complete' ? init() : window.onload = init;
  7. function init() {
  8.     // generate some random data
  9.     var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = [];
  10.     for (var i = 0; i < 200; i++) {
  11.         data.push({
  12.             id: i,
  13.             country: countries[i % countries.length],
  14.             sales: Math.random() * 10000,
  15.             expenses: Math.random() * 5000,
  16.         });
  17.     }
  18.     // show data in a grid
  19.     var theGrid = new FlexGrid('#theGrid', {
  20.         isReadOnly: false,
  21.         allowResizing: 'None',
  22.         allowDragging: 'None',
  23.         allowSorting: false,
  24.         selectionMode: 'RowRange',
  25.         alternatingRowStep: 0,
  26.         autoGenerateColumns: false,
  27.         columns: [
  28.             { binding: 'id', header: 'ID', width: 50 },
  29.             { binding: 'country', header: 'Country' },
  30.             { binding: 'sales', header: 'Sales', width: 80, format: 'n0' },
  31.             { binding: 'salesDiff', header: 'Diff', dataType: 'Number', width: 80, format: 'p0' },
  32.             { binding: 'expenses', header: 'Expenses', width: 80, format: 'n0' },
  33.             { binding: 'expensesDiff', header: 'Diff', dataType: 'Number', width: 80, format: 'p0' }
  34.         ],
  35.         itemsSource: data,
  36.     });
  37.     // insert extra column header row
  38.     var ch = theGrid.columnHeaders, hr = new Row();
  39.     ch.rows.insert(0, hr);
  40.     // fill out headings in extra header row
  41.     for (var i = 0; i < theGrid.columns.length; i++) {
  42.         var hdr = ch.getCellData(1, i, false);
  43.         if (hdr == 'Diff')
  44.             hdr = ch.getCellData(1, i - 1, false);
  45.         ch.setCellData(0, i, hdr);
  46.     }
  47.     // allow merging across and down extra header row
  48.     theGrid.allowMerging = AllowMerging.ColumnHeaders;
  49.     hr.allowMerging = true;
  50.     theGrid.columns[0].allowMerging = true;
  51.     theGrid.columns[1].allowMerging = true;
  52.     // custom rendering for headers and "Diff" columns
  53.     theGrid.formatItem.addHandler(function (s, e) {
  54.         // center-align column headers
  55.         if (e.panel == s.columnHeaders) {
  56.             e.cell.innerHTML = '<div class="v-center">' +
  57.                 e.cell.innerHTML + '</div>';
  58.         }
  59.         // custom rendering for "Diff" columns
  60.         if (e.panel == s.cells) {
  61.             var col = s.columns[e.col];
  62.             if (e.row >= 0 && (col.binding == 'sales' || col.binding == 'expenses')) {
  63.                 var val = s.getCellData(e.row, e.col);
  64.                 e.cell.innerText = val+'';
  65.             }
  66.         }
  67.     });
  68. }
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
醉汀雨笙
金牌服务用户   /  发表于:2020-9-24 11:32:06
板凳
已解决,谢谢!
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-9-24 12:03:37
地板
不客气,感谢反馈,本帖结贴了,有新的问题欢迎发新帖交流~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部