如何更改jqgrid中的行位置?

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

我正在将jqgrid与MVC一起使用,现在,我想在单击^时获得行位置并反过来更改行位置。

实际上,我想在每一行设置'up'和'down'标志以更改一级行的位置

有人可以帮助我吗?!

jqgrid jqgrid-asp.net mvcjqgrid
1个回答
1
投票

有很多可能的解决方案。其中之一是使用自定义格式器定义按钮,然后在loadComplete上绑定事件以使用jquery移动行。代码下方:

        $("#jqGrid").jqGrid({
            datatype: "local",
            data: mydata,
            height: 250,
            width: 780,
            colModel: [
                { label :'move', formatter : myformatter, width:95},
                { label: 'Inv No', name: 'id', width: 75, key:true },
                { label: 'Date', name: 'invdate', width: 90 },
                { label: 'Client', name: 'name', width: 100 },
                { label: 'Amount', name: 'amount', width: 80 },
                { label: 'Tax', name: 'tax', width: 80 },
                { label: 'Total', name: 'total', width: 80 },
                { label: 'Notes', name: 'note', width: 150 }
            ],
            viewrecords: true, // show the current page, data rang and total records on the toolbar
            caption: "Load jqGrid through Javascript Array",
            loadComplete : function() {
              $(".up,.down").on('click', function () {
                 var row = $(this).closest("tr.jqgrow");
                 if($(this).is('.up')){
                    row.insertBefore(row.prev());
                 } else {
                    row.insertAfter(row.next());
                 }                    
              });
            }
        });
        function myformatter() {
            return '<button class="up" >Up</button>' + '<button class="down">Down</button>';
        }

演示here

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