js设置datagriad的行移动

   //                    ,
//                formatter: function(value,row,index){
//                    var download = row.priority+
//                        "&nbsp;&nbsp;&nbsp;<a href=\"#\" id = \"V_up_"+index+"\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-add'\" onclick=moveUp(this,"
//                                + index+ ","+row.priority+","+row.id+")>上移</a>"
//                                 +"<a href=\"#\" id = \"V_down_"+index+"\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-add'\" onclick=movedown(this,"
//                                + index+ ")>下移</a>";
//                    return download;
//                    }
function moveUp(value, index, priority,id) { var $tr = $(value).parents("tr"); if ($tr.index() != 0) { $tr.fadeOut().fadeIn(); $tr.prev().before($tr); } var columns = $('#dataGrid').datagrid("options").columns; // 得到rows对象 var rows = $('#dataGrid').datagrid("getRows"); // 这段代码是// 对某个单元格赋值 var changeRows = ""; var beichangeRows =""; if(index == 0){ beichangeRows = 2; changeRows = 1; }else{ changeRows = rows[index-1].priority; beichangeRows = priority; } //进入后台更新优先级 updatePriority(rows[index].id+"@"+changeRows,rows[index-1].id+"@"+beichangeRows); } function movedown(value, index,row) { var len = value.length; var $tr = $(value).parents("tr"); if ($tr.index() != len - 1) { $tr.fadeOut().fadeIn(); $tr.next().after($tr); } var columns = $('#dataGrid').datagrid("options").columns; // 得到rows对象 var rows = $('#dataGrid').datagrid("getRows"); // 这段代码是// 对某个单元格赋值 var changeRows = ""; var beichangeRows =""; if(index == len - 1){ beichangeRows =rows[index].priority; changeRows = rows[index+1].priority;; updatePriority(rows[index].id+"@"+changeRows,rows[index+1].id+"@"+beichangeRows); } }



    /**
     * 更新优先级
     * @param changeRows
     * @param beichangeRows
     */
    
    function updatePriority(changeRows,beichangeRows){
         $.ajax({
                url: '../productConfig/updatePriority',
                data: {"changeRows":changeRows,"beichangeRows":beichangeRows},
                type: 'post',
                dataType: 'json',
                success: function(r) {
                     $('#dataGrid').datagrid("reolad")
                }
            });
    }

 

posted @ 2015-09-14 15:59  tian830937  阅读(218)  评论(0编辑  收藏  举报