简体   繁体   English

用角6重新排列Kendo网格行

[英]Reorder Kendo grid row with angular 6

I have used the same code as used to implement the row reorder feature in the example given here https://www.telerik.com/kendo-angular-ui/components/grid/how-to/row-reordering 我在这里给出的示例中使用了与实现行重新排序功能相同的代码https://www.telerik.com/kendo-angular-ui/components/grid/how-to/row-reordering

private handleDragAndDrop(): Subscription {
const sub = new Subscription(() => { });
let draggedItemIndex;

const tableRows = Array.from(document.querySelectorAll('.k-grid-content       
tr'));
tableRows.forEach(item => {
this.renderer.setAttribute(item, 'draggable', 'true');
const dragStart = fromEvent(item, 'dragstart');
const dragOver = fromEvent(item, 'dragover');
const drop = fromEvent(item, 'drop');

sub.add(dragStart.pipe(
tap(({ dataTransfer }) => {
try {
// Firefox won't drag without setting data
dataTransfer.setData('application/json', {});
} catch (err) {
// IE doesn't support MIME types in setData
}
})
).subscribe(({ target }) => {
draggedItemIndex = target.rowIndex;
}));

sub.add(dragOver.subscribe((e: any) => e.preventDefault()));

sub.add(drop.subscribe((e: any) => {
e.preventDefault();
const dataItem = this.gridData.data.splice(draggedItemIndex, 1)[0];
const dropIndex = closest(e.target, tableRow).rowIndex;
this.zone.run(() =>
this.gridData.data.splice(dropIndex, 0, dataItem)
);
}));
});

`-------------------------- I am receiving below error for the above code `--------------------------我收到上述代码的以下错误

error TS2459: Type 'Event' has no property 'dataTransfer' and no string index signature. 错误TS2459:“事件”类型没有属性“ dataTransfer”,也没有字符串索引签名。 error TS2339: Property 'rowIndex' does not exist on type 'EventTarget'. 错误TS2339:类型“ EventTarget”上不存在属性“ rowIndex”。

Simply change following line - 只需更改以下行-

// Firefox won't drag without setting data
dataTransfer.setData('application/json', '');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM