请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

eeg1412

注册会员

12

主题

20

帖子

82

积分

注册会员

积分
82
eeg1412
注册会员   /  发表于:2020-6-17 20:52  /   查看:3133  /  回复:3
1金币
这边用了
https://demo.grapecity.com.cn/wijmo/demos/Grid/Editing/CustomEditors/vue
这个例子中的自定义编辑器。
因为我们的需求是默认数字这里显示为空所以给amount设置了null。
然后在空白的情况下,强行用输入法输入中文的话就会报
index.js:14 Uncaught TypeError: Cannot read property 'indexOf' of null
    at eval (VM85 index.js:14)
因为我们这个项目前端如果遇到报错是会强制跳转到登录页面的,所以不知道有没有解决办法。
代码如下,插入到上面的地址中即可。
  1. <template>
  2.     <div class="container-fluid">
  3.         <!-- the grid -->
  4.         <wj-flex-grid
  5.             keyActionTab="CycleOut"
  6.             :itemsSource="data"
  7.             :initialized="initializeGrid">
  8.             <wj-flex-grid-column binding="id" header="ID" :width=40 :isReadOnly=true></wj-flex-grid-column>
  9.             <wj-flex-grid-column binding="date" header="Date" format="d"></wj-flex-grid-column>
  10.             <wj-flex-grid-column binding="time" header="Time" format="t"></wj-flex-grid-column>
  11.             <wj-flex-grid-column binding="country" header="Country"></wj-flex-grid-column>
  12.             <wj-flex-grid-column binding="product" header="Product"></wj-flex-grid-column>
  13.             <wj-flex-grid-column binding="amount" header="Amount" format="n2"></wj-flex-grid-column>
  14.         </wj-flex-grid>
  15.     </div>
  16. </template>

  17. <script>
  18. import "@grapecity/wijmo.styles/wijmo.css";
  19. import "bootstrap.css";
  20. import Vue from "vue";
  21. import "@grapecity/wijmo.vue2.grid";
  22. import * as wjcCore from '@grapecity/wijmo';
  23. import * as wjcGrid from '@grapecity/wijmo.grid';
  24. import * as wjcInput from '@grapecity/wijmo.input';
  25. import { CustomGridEditor } from './customEditor';

  26. new Vue({
  27.           el: "#app",
  28.           data: {
  29.         data: null,
  30.         countries: ['US', 'Germany', 'UK' ,'Japan', 'Italy', 'Greece'],
  31.         products: [
  32.             { id: 0, name: 'Widget', unitPrice: 23.43 },
  33.             { id: 1, name: 'Gadget', unitPrice: 12.33 },
  34.             { id: 2, name: 'Doohickey', unitPrice: 53.07 }
  35.         ]
  36.           },
  37.         methods:{
  38.                 initializeGrid(flex){
  39.             this.data = this._getData();
  40.             // add custom editors to the grid
  41.             new CustomGridEditor(flex, 'date', wjcInput.InputDate, {
  42.                 format: 'd'
  43.             });
  44.             new CustomGridEditor(flex, 'time', wjcInput.InputTime, {
  45.                 format: 't',
  46.                 min: new Date(2000, 1, 1, 7, 0),
  47.                 max: new Date(2000, 1, 1, 22, 0),
  48.                 step: 30
  49.             });
  50.             new CustomGridEditor(flex, 'country', wjcInput.ComboBox, {
  51.                 itemsSource: this.countries
  52.             });
  53.             new CustomGridEditor(flex, 'amount', wjcInput.InputNumber, {
  54.                 max: 99999999999999,
  55.                 min: -9999999999999,
  56.                 showSpinner: false,
  57.                 step: 1,
  58.                 format: 'n0',
  59.                 isRequired: false,
  60.             });
  61.             // create an editor based on a ComboBox
  62.             let multiColumnEditor = new CustomGridEditor(flex, 'product', wjcInput.ComboBox, {
  63.                 headerPath: 'name',
  64.                 displayMemberPath: 'name',
  65.                 itemsSource: this.products
  66.             });
  67.             // customize the ComboBox to show multiple columns
  68.             let combo = multiColumnEditor.control;
  69.             combo.listBox.formatItem.addHandler((s, e) => {
  70.                 e.item.innerHTML = '<table><tr>' +
  71.                 '<td style="width:30px;text-align:right;padding-right:6px">' + e.data.id + '</td>' +
  72.                 '<td style="width:100px;padding-right:6px"><b>' + e.data.name + '</b></td>' +
  73.                 '<td style="width:80px;text-align:right;padding-right:6px">' +
  74.                 wjcCore.Globalize.format(e.data.unitPrice, 'c') +
  75.                 '</td>' +
  76.                 '</tr></table>';
  77.             });
  78.                 },
  79.                 _getData() {
  80.             // create some random data
  81.             let data = [];
  82.             let dt = new Date();
  83.             for (let i = 0; i < 100; i++) {
  84.                 data.push({
  85.                     id: i,
  86.                     date: new Date(dt.getFullYear(), i % 12, 25, i % 24, i % 60, i % 60),
  87.                     time: new Date(dt.getFullYear(), i % 12, 25, i % 24, i % 60, i % 60),
  88.                     country: this.countries[Math.floor(Math.random() * this.countries.length)],
  89.                     product: this.products[Math.floor(Math.random() * this.products.length)].name,
  90.                     amount: null,
  91.                     discount: Math.random() / 4
  92.                 });
  93.             }
  94.             return data;
  95.                 }
  96.         }
  97. });
  98. </script>

  99. <style>
  100.         .wj-flexgrid {
  101.         height: 300px;
  102.         margin-bottom: 12px;
  103.     }

  104.     .wj-flexgrid .wj-cell {
  105.         padding: 6px 3px;
  106.     }

  107.     body {
  108.         margin-bottom: 24px;
  109.     }
  110. </style>

复制代码
具体操作是在Amount底下,用中文输入法输入中文,就会在浏览器的控制台中报错。

最佳答案

查看完整内容

你好,这个问题比较麻烦,我详细解释一下: 首先,在线示例中Vue版本的示例看不到完整代码,建议对照官网下载的产品包中以下路径的完整示例: wijmo-5.20201.663\samples\Grid\CustomCells\CustomEditors\vue 或者对照purejs版本的示例中,针对CustomGridEditor的具体实现来看: https://demo.grapecity.com.cn/wijmo/demos/Grid/Editing/CustomEditors/purejs 实际上CustomGridEditor是一个自定义的类,通过利用FlexGrid ...

3 个回复

倒序浏览
最佳答案
最佳答案
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-6-17 20:52:53
来自 4#
你好,这个问题比较麻烦,我详细解释一下:

首先,在线示例中Vue版本的示例看不到完整代码,建议对照官网下载的产品包中以下路径的完整示例:
wijmo-5.20201.663\samples\Grid\CustomCells\CustomEditors\vue
或者对照purejs版本的示例中,针对CustomGridEditor的具体实现来看:
https://demo.grapecity.com.cn/wi ... ustomEditors/purejs

实际上CustomGridEditor是一个自定义的类,通过利用FlexGrid原生的事件来实现替换编辑组件,实现“自定义”编辑组件的需求。

目前来讲,CustomGridEditor类只针对页面上用到的三种下拉组件做了实现,想实现这里的InputNumber,需要在这个基础上做一定修改,推荐参考这篇文章:

https://gcdn.grapecity.com.cn/fo ... &extra=page%3D1
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-6-18 09:00:20
2#
你好,正在调研这个问题,预计12点30前回复。
回复 使用道具 举报
eeg1412
注册会员   /  发表于:2020-6-18 15:51:29
3#
KevinChen 发表于 2020-6-18 09:00
你好,正在调研这个问题,预计12点30前回复。

你好,有进展了吗?
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部