kendo网格行在运行时滑动

时间:2018-09-26 08:40:52

标签: javascript angularjs kendo-grid

我想连续刷两行。下面是我的Kendo网格。第一次单击第一行的向下按钮后,它可以正常工作(内部更改为前两行),但是接下来再次单击第一行的向下按钮,则不能工作我期望(此阶段的内部更改发生在第二行和第三行之间),因为我更改了seqNo并按seqNo对网格进行了排序,但索引保持不变。

enter image description here

代码

 vm.gridOptions =
        {
            dataSource: vm.dataSource,
            sortable: false,
            selectable: true,
            filterable: false,
            scrollable: true,
            pageable: false,
            height: 222,
            columns:
            [
                { title: "...", width: "4%", headerAttributes: { style: "font-weight:bold;text-align:center;" }, attributes: { style: "text-align:center;" }, template: "<span ng-click='vm.downItem(dataItem)' class='btn btn-success btn-xs glyphicon glyphicon-arrow-down' />" },
                { field: "code", title: "Code", width: "10%", headerAttributes: { style: "text-align:center;font-weight: bold;" }, attributes: { style: "text-align:center;" } },
                { field: "name", title: "Name", width: "25%", headerAttributes: { style: "font-weight: bold;" } },
                { field: "reportOrder", title: "Seq No", width: "6%", headerAttributes: { style: "text-align:center;font-weight:bold" }, attributes: { style: "text-align:center;margin:0;padding:1px;" }, template: "<input type='number' class='editable-grid-entry' placeholder='Report Order...' style='text-align:center;width:100%;box-sizing:border-box;' ng-model='dataItem.reportOrder'/>" },
            ]
        };

this.downItem = function ( dataItem )
    {
        var index = vm.dataSource.indexOf( dataItem );
        var totalRow = vm.dataSource._data.length;

        var holdSeq = vm.dataSource._data[index + 1].reportOrder;
        vm.dataSource._data[index + 1].reportOrder = dataItem.reportOrder;
        vm.dataSource._data[index].reportOrder = holdSeq;

        vm.dataSource.sort( { field: "reportOrder", dir: "asc" } );
    }

请帮助我应该纠正的地方,或者建议我一种使用更改序列号连续滑动两行的解决方案。

1 个答案:

答案 0 :(得分:1)

尝试

  this.downItem = function ( dataItem )
    {
        var index = vm.dataSource.indexOf( dataItem );
        var downItemValue = dataItem.reportOrder;

        for ( var rowIdx = 0; rowIdx < vm.dataSource._data.length; rowIdx++ )
        {
            if ( vm.dataSource._data[rowIdx].reportOrder == ( dataItem.reportOrder + 1 ) )
            {
                vm.dataSource._data[index].reportOrder = vm.dataSource._data[rowIdx].reportOrder;

                vm.dataSource._data[rowIdx].reportOrder = downItemValue;
                break;
            }

        }

        vm.dataSource.sort( { field: "reportOrder", dir: "asc" } );
    }