使用自定义粘贴功能时如何触发Kendo Jquery电子表格的更改事件?

问题描述 投票:0回答:1

我尝试了下面的自定义粘贴功能,仅粘贴值,但它不会触发change事件,以便我将数据同步到数据源。

Dojo Demo Link

...
change: onExcelChange,
paste: function(e) {
            e.preventDefault()

            var currentRange = e.range;
            var fullData = e.clipboardContent.data;
            var mergedCells = e.clipboardContent.mergedCells;
            var topLeft = currentRange.topLeft();
            var initialRow = topLeft.row;
            var initialCol = topLeft.col;
            var origRef = e.clipboardContent.origRef;
            var numberOfRows = origRef.bottomRight.row - origRef.topLeft.row + 1;
            var numberOfCols = origRef.bottomRight.col - origRef.topLeft.col + 1;
            var spread = e.sender;
            var sheet = spread.activeSheet();
            var rangeToPaste =  sheet.range(initialRow, initialCol, numberOfRows, numberOfCols);

            sheet.batch(function() {
                for(var i = 0; i < fullData.length; i += 1) {
                    var currentFullData = fullData[i];

                    for(var j = 0; j < currentFullData.length; j += 1 ) {
                        var range = sheet.range(initialRow + i, initialCol + j);
                        var value = currentFullData[j].value;

                        if (value !== null) {
                            range.input(value);
                            range.format(null);
                        }
                    }
                }
                 sheet.select(rangeToPaste);
            }, { layout: true, recalc: true });        
        } ...

我尝试在sheet.batch中使用recalc:true来触发更改,但无济于事。任何帮助将不胜感激。

kendo-ui kendospreadsheet
1个回答
0
投票

所有Kendo小部件inherit from Observable,它具有trigger方法:

var obj = new kendo.Observable();
obj.bind("myevent", function(e) {
    console.log(e.data); // outputs "data"
});
obj.trigger("myevent", { data: "data" });

您需要使用正确的参数手动触发Spreadheet的change event

© www.soinside.com 2019 - 2024. All rights reserved.