你好,这需要把\n替换为<br>,参考代码:
- $(document).ready(function () {
- var gridElement = $("#theGrid");
- gridElement.height($(document).height() - 50);
- gridElement.width($(document).width() - 5);
- var testStr = $("#testString").text();
- // create some random data
- data = [];
- for (var i = 0; i < 10; i++) {
- data.push({
- country: 'Ramdom....',
- downloads: testStr,
- sales: Math.random() * 10000,
- expenses: Math.random() * 5000,
- expenses2: Math.random() * 5000,
- expenses3: Math.random() * 5000,
- expenses4: Math.random() * 5000,
- expenses5: new Date(),
- });
- }
- // create CollectionView on the data (to get events)
- var view = new wijmo.collections.CollectionView(data);
- // initialize the grid
- var grid = new wijmo.grid.FlexGrid('#theGrid', {
- itemsSource: view,
- selectionMode: wijmo.grid.SelectionMode.Cell,
- allowAddNew: true,
- allowDelete: true,
- autoSizeMode: wijmo.grid.AutoSizeMode.Both
- });
- var downloadsColumn = grid.columns.getColumn("downloads");
- downloadsColumn.wordWrap = true;
- downloadsColumn.isContentHtml = true;
- grid.autoSizeRows(0, grid.rows.length, false, 40);
- grid.itemFormatter = function (panel, r, c, cell) {
- //check for column
- if (c == 1) {
- //get the data
- var data = panel.getCellData(r, c);
- //replace \n with <br/> tags
- var formattedData = data.replace(/\n/g, '<br/>');
- //set the formatted data
- panel.setCellData(r, c, formattedData);
-
- }
- setTimeout(grid.invalidate(), 1);
- grid.autoSizrR
- }
- });
复制代码
关键代码:
- grid.itemFormatter = function (panel, r, c, cell) {
- //check for column
- if (c == 1) {
- //get the data
- var data = panel.getCellData(r, c);
- //replace \n with <br/> tags
- var formattedData = data.replace(/\n/g, '<br/>');
- //set the formatted data
- panel.setCellData(r, c, formattedData);
-
- }
- setTimeout(grid.invalidate(), 1);
- grid.autoSizrR
- }
复制代码 |