1金币
本帖最后由 老赵头 于 2024-10-25 17:18 编辑
自定义行操作Check,option对象内iconSelector(item: any, index)方法内[item.Id]为undefined,导致勾选状态无法写入。
请查看93行和123行的打印值
- const initSpread = function (spread) {
- spreadEntity = spread;
- spread.suspendPaint();
- spread.clearSheets();
- spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader; // 列宽自适应
- // init a data manager
- const dataManager = spread.dataManager();
- spread.options.allowDynamicArray = true; // 是否启用动态数组
- const myTable = dataManager.addTable('myTable', {
- batch: false,
- autoSync: false,
- data: [
- {
- empNo: 'DE001',
- Id: 1,
- stringType: 'Jone',
- numberType: 90.012,
- currencyType: 8.5,
- urlLink: 'http://www.baidu.com',
- phone: '(123)555-0100',
- selectType: 1,
- dateType: '2019-07-04',
- credit: '30,25',
- createTimeType: null,
- isFinished: 'Yes',
- isEncouraged: 'True',
- checkboxType: true,
- buttonList: undefined,
- radioButtonList: 0,
- },
- {
- empNo: 'DE002',
- Id: 2,
- stringType: 'Tom',
- numberType: 90.012,
- currencyType: 8.5,
- urlLink: 'http://www.baidu.com',
- phone: '(123)555-0101',
- selectType: 2,
- dateType: '2019-07-04',
- credit: '30,25',
- createTimeType: null,
- isFinished: 'Yes',
- isEncouraged: 'True',
- checkboxType: false,
- checkboxTypeButton: false,
- },
- {
- empNo: 'DE003',
- Id: 3,
- stringType: 'Kotas',
- numberType: 90.012,
- currencyType: 8.5,
- urlLink: 'http://www.baidu.com',
- phone: '(123)555-0101',
- selectType: 1,
- dateType: '2019-07-04',
- credit: '30,25',
- createTimeType: null,
- isFinished: 'No',
- isEncouraged: 'False',
- checkboxType: true,
- checkboxTypeButton: true,
- }
- ],
- schema: {},
- });
- // init a table sheet
- const sheet = spread.addSheetTab(
- 0,
- config.sheetName || 'Sheet1',
- GC.Spread.Sheets.SheetType.tableSheet,
- );
- // actions
- const rowActions = GC.Spread.Sheets.TableSheet.BuiltInRowActions;
- const options = sheet.rowActionOptions();
- if (config.allowDelete) {
- options.push(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
- ],
- tooltip: 'Check/Uncheck',
- iconSelector(item, index) {
- console.log('item:', item, 'item.Id:', item.Id); // item: {YTi: currentIndex} item.Id:undefined
- return !!checkMap[item.Id];
- },
- command: CheckRow,
- });
- }
- sheet.rowActionOptions(options);
- // bind a view to the table sheet
- myTable.fetch().then(function () {
- const view = myTable.addView('myView', tableViewTransfer(config.columns));
- sheet.setDataView(view);
- });
- spread.resumePaint();
- };
- ......
- const registerCommands = () => {
- const { Commands } = GC.Spread.Sheets;
- Commands[CheckRow] = {
- canUndo: false,
- execute(context, options) {
- const id = options.item.Id;
- console.log('options.item.Id:', options.item.Id); // options.item.Id: 1、2、3
- checkMap[id] = !checkMap[id];
- return true;
- },
- };
- };
复制代码
|
|