您好,默认情况下,显示的数据小数位为2,这个可以在columns的设置中进行修改,如图:
图中,n后边的数字就是希望保留的位数。
而实际上,这只是作为格式化来处理的,不会影响cell的真实值。
计算行为引用的是cell的真实数据,如果您的计算结果不正确,请检查其他的原因。
如果实在想显示真实位数,请参考这篇示例:
https://demo.grapecity.com.cn/wi ... ionalStyling/purejs
把app.js改为:
- import 'bootstrap.css';
- import '@grapecity/wijmo.styles/wijmo.css';
- import './styles.css';
- import { Globalize } from '@grapecity/wijmo';
- import { FlexGrid, Row, AllowMerging } from '@grapecity/wijmo.grid';
- document.readyState === 'complete' ? init() : window.onload = init;
- function init() {
- // generate some random data
- var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = [];
- for (var i = 0; i < 200; i++) {
- data.push({
- id: i,
- country: countries[i % countries.length],
- sales: Math.random() * 10000,
- expenses: Math.random() * 5000,
- });
- }
- // show data in a grid
- var theGrid = new FlexGrid('#theGrid', {
- isReadOnly: false,
- allowResizing: 'None',
- allowDragging: 'None',
- allowSorting: false,
- selectionMode: 'RowRange',
- alternatingRowStep: 0,
- autoGenerateColumns: false,
- columns: [
- { binding: 'id', header: 'ID', width: 50 },
- { binding: 'country', header: 'Country' },
- { binding: 'sales', header: 'Sales', width: 80, format: 'n0' },
- { binding: 'salesDiff', header: 'Diff', dataType: 'Number', width: 80, format: 'p0' },
- { binding: 'expenses', header: 'Expenses', width: 80, format: 'n0' },
- { binding: 'expensesDiff', header: 'Diff', dataType: 'Number', width: 80, format: 'p0' }
- ],
- itemsSource: data,
- });
- // insert extra column header row
- var ch = theGrid.columnHeaders, hr = new Row();
- ch.rows.insert(0, hr);
- // fill out headings in extra header row
- for (var i = 0; i < theGrid.columns.length; i++) {
- var hdr = ch.getCellData(1, i, false);
- if (hdr == 'Diff')
- hdr = ch.getCellData(1, i - 1, false);
- ch.setCellData(0, i, hdr);
- }
- // allow merging across and down extra header row
- theGrid.allowMerging = AllowMerging.ColumnHeaders;
- hr.allowMerging = true;
- theGrid.columns[0].allowMerging = true;
- theGrid.columns[1].allowMerging = true;
- // custom rendering for headers and "Diff" columns
- theGrid.formatItem.addHandler(function (s, e) {
- // center-align column headers
- if (e.panel == s.columnHeaders) {
- e.cell.innerHTML = '<div class="v-center">' +
- e.cell.innerHTML + '</div>';
- }
- // custom rendering for "Diff" columns
- if (e.panel == s.cells) {
- var col = s.columns[e.col];
- if (e.row >= 0 && (col.binding == 'sales' || col.binding == 'expenses')) {
- var val = s.getCellData(e.row, e.col);
- e.cell.innerText = val+'';
- }
- }
- });
- }
复制代码
|