你好,插入新行的逻辑请参考以下代码:
app.js
- import 'bootstrap.css';
- import '@grapecity/wijmo.styles/wijmo.css';
- import { SortDescription, format } from '@grapecity/wijmo';
- import { FlexGrid } from '@grapecity/wijmo.grid';
- document.readyState === 'complete' ? init() : window.onload = init;
- function init() {
- // create some random data
- var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(',');
- var data = [];
- for (var i = 0; i < countries.length; i++) {
- data.push({
- id: i,
- country: countries[i],
- sales: Math.random() * 10000,
- expenses: Math.random() * 5000
- });
- }
- // bind a grid to the raw data
- var theGrid = new FlexGrid('#theGrid', {
- allowSorting: false,
- showSort: false,
- autoGenerateColumns: false,
- columns: [
- { binding: 'country', header: 'Country', width: '2*' },
- { binding: 'sales', header: 'Sales', width: '*', format: 'n2' },
- { binding: 'expenses', header: 'Expenses', width: '*', format: 'n2' }
- ],
- itemsSource: data
- });
- document.getElementById("insertRows").addEventListener("click",function(){
- console.log(1);
- theGrid.itemsSource.splice(2,0,{
- id: 0,
- country: "",
- sales: "",
- expenses: ""
- })
- theGrid.itemsSource.splice(2,0,{
- id: 0,
- country: "",
- sales: "",
- expenses: ""
- })
- theGrid.itemsSource.splice(2,0,{
- id: 0,
- country: "",
- sales: "",
- expenses: ""
- })
- theGrid.itemsSource.splice(2,0,{
- id: 0,
- country: "",
- sales: "",
- expenses: ""
- })
- theGrid.itemsSource.splice(2,0,{
- id: 0,
- country: "",
- sales: "",
- expenses: ""
- })
- theGrid.collectionView.refresh();
- });
- }
复制代码
index.html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title>GrapeCity Wijmo FlexGrid Arrays and CollectionViews Binding</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <!-- SystemJS -->
- <script src="node_modules/systemjs/dist/system.src.js"></script>
- <script src="systemjs.config.js"></script>
- <script>
- System.import('./src/app');
- </script>
- </head>
- <body>
- <div class="container-fluid">
- <p id="selectedItem"></p>
- <button id="insertRows">插入5行</button>
- <div id="theGrid"></div>
- </div>
- </body>
- </html>
复制代码
测试地址:
https://demo.grapecity.com.cn/wi ... nding/Basics/purejs
|