wijimo grid字段小數點顯示問題
1.問題 使用wijmo grid 給表格賦值,其中有一個字段本身的小數位數是5位的,但是綁定到grid 後,自動只顯示兩位小數點。在你們的官網測試,也是只顯示兩位小數點,如何要數據顯示本身正常的小數位數,其中別的字段使用到該字段計算的問題,導致結果相差甚遠。a.在實例中測試:添加小數位
b.編輯結束後,點擊鼠標結束編輯還是兩位小數
您好,默认情况下,显示的数据小数位为2,这个可以在columns的设置中进行修改,如图:
图中,n后边的数字就是希望保留的位数。
而实际上,这只是作为格式化来处理的,不会影响cell的真实值。
计算行为引用的是cell的真实数据,如果您的计算结果不正确,请检查其他的原因。
如果实在想显示真实位数,请参考这篇示例:
https://demo.grapecity.com.cn/wijmo/demos/Grid/CustomCells/ConditionalStyling/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,
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.allowMerging = true;
theGrid.columns.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;
if (e.row >= 0 && (col.binding == 'sales' || col.binding == 'expenses')) {
var val = s.getCellData(e.row, e.col);
e.cell.innerText = val+'';
}
}
});
}
已解决,谢谢! 不客气,感谢反馈,本帖结贴了,有新的问题欢迎发新帖交流~
页:
[1]