找回密码
 立即注册

QQ登录

只需一步,快速开始

mtkj
金牌服务用户   /  发表于:2020-7-28 14:15  /   查看:3237  /  回复:7
在已经搜索的页面上 在指定行位置插入多行

7 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-28 15:50:12
沙发
你好,FlexGrid中行对应的对象是Row,FlexGrid对象里有个rows属性,对应了RowCollection类,这个类用来管理flexGrid的row,可以用来insert空行。
回复 使用道具 举报
mtkj
金牌服务用户   /  发表于:2020-7-28 16:28:16
板凳
页面上如何刷新出来呢?
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-28 19:18:05
地板
你好,经测试,insert方法可以直接显示出新插入的行,如代码所示:

  1. import 'bootstrap.css';
  2. import '@grapecity/wijmo.styles/wijmo.css';
  3. import './styles.css';
  4. import * as wjGrid from '@grapecity/wijmo.grid';
  5. //
  6. document.readyState === 'complete' ? init() : window.onload = init;
  7. //
  8. function init() {
  9.     //
  10.     // generate some random data
  11.     var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = [];
  12.     for (var i = 0; i < countries.length; i++) {
  13.         data.push({
  14.             country: countries[i],
  15.             downloads: Math.round(Math.random() * 20000),
  16.             sales: Math.random() * 10000,
  17.             expenses: Math.random() * 5000
  18.         });
  19.     }
  20.     //
  21.     // grid with extra fixed row and a footer row
  22.     var theGrid = new wjGrid.FlexGrid('#theGrid');
  23.     var row = new wjGrid.Row();
  24.     console.log(row.visible);
  25.     theGrid.itemsSource = data; // bind the grid
  26.     theGrid.rows.insert(2,new wjGrid.Row());
  27.     theGrid.rows.insert(2,new wjGrid.Row());
  28.     theGrid.rows.insert(2,new wjGrid.Row());
  29.     theGrid.rows.insert(2,new wjGrid.Row());
  30. }
复制代码


测试地址:
https://demo.grapecity.com.cn/wi ... /Collections/purejs

请注意,插入新行的操作需要放到绑定数据源之后,如果之前插入新行,绑定数据源后会导致重新生成行。如图:

本帖子中包含更多资源

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

x
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-29 11:33:17
5#
你好,插入新行的逻辑请参考以下代码:


app.js

  1. import 'bootstrap.css';
  2. import '@grapecity/wijmo.styles/wijmo.css';
  3. import { SortDescription, format } from '@grapecity/wijmo';
  4. import { FlexGrid } from '@grapecity/wijmo.grid';
  5. document.readyState === 'complete' ? init() : window.onload = init;
  6. function init() {
  7.     // create some random data
  8.     var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(',');
  9.     var data = [];
  10.     for (var i = 0; i < countries.length; i++) {
  11.         data.push({
  12.             id: i,
  13.             country: countries[i],
  14.             sales: Math.random() * 10000,
  15.             expenses: Math.random() * 5000
  16.         });
  17.     }
  18.     // bind a grid to the raw data
  19.     var theGrid = new FlexGrid('#theGrid', {
  20.         allowSorting: false,
  21.         showSort: false,
  22.         autoGenerateColumns: false,
  23.         columns: [
  24.             { binding: 'country', header: 'Country', width: '2*' },
  25.             { binding: 'sales', header: 'Sales', width: '*', format: 'n2' },
  26.             { binding: 'expenses', header: 'Expenses', width: '*', format: 'n2' }
  27.         ],
  28.         itemsSource: data
  29.     });

  30.     document.getElementById("insertRows").addEventListener("click",function(){
  31.         console.log(1);
  32.         theGrid.itemsSource.splice(2,0,{
  33.             id: 0,
  34.             country: "",
  35.             sales: "",
  36.             expenses: ""
  37.         })
  38.         theGrid.itemsSource.splice(2,0,{
  39.             id: 0,
  40.             country: "",
  41.             sales: "",
  42.             expenses: ""
  43.         })
  44.         theGrid.itemsSource.splice(2,0,{
  45.             id: 0,
  46.             country: "",
  47.             sales: "",
  48.             expenses: ""
  49.         })
  50.         theGrid.itemsSource.splice(2,0,{
  51.             id: 0,
  52.             country: "",
  53.             sales: "",
  54.             expenses: ""
  55.         })
  56.         theGrid.itemsSource.splice(2,0,{
  57.             id: 0,
  58.             country: "",
  59.             sales: "",
  60.             expenses: ""
  61.         })
  62.         theGrid.collectionView.refresh();
  63.     });

  64. }
复制代码


index.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <title>GrapeCity Wijmo FlexGrid Arrays and CollectionViews Binding</title>
  7.     <meta name="viewport" content="width=device-width, initial-scale=1.0">

  8.     <!-- SystemJS -->
  9.     <script src="node_modules/systemjs/dist/system.src.js"></script>
  10.     <script src="systemjs.config.js"></script>
  11.     <script>
  12.         System.import('./src/app');
  13.     </script>
  14. </head>
  15. <body>
  16. <div class="container-fluid">
  17.     <p id="selectedItem"></p>
  18.     <button id="insertRows">插入5行</button>
  19.     <div id="theGrid"></div>
  20. </div>
  21. </body>
  22. </html>
复制代码


测试地址:
https://demo.grapecity.com.cn/wi ... nding/Basics/purejs

回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-29 15:34:18
6#
回复 使用道具 举报
mtkj
金牌服务用户   /  发表于:2020-7-30 11:11:42
7#
十分感谢 本贴问题已经解决
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-30 11:34:24
8#
感谢反馈,帖子结贴了~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部