easyui-datagrid 行【上移】,【下移】

直接源码可以拿来直接使用:
参数说明:
index: 行索引
type:‘up’ , ‘down’
gridname: datagrid id
sortname: 排序号(如果不需要可以自行删除,但是列表终归要排序的)

 mysort:function(index, type, gridname,sortname) {
        if ("up" == type) {
            if (index != 0) {
                var toup = $('#' + gridname).datagrid('getData').rows[index];
                var todown = $('#' + gridname).datagrid('getData').rows[index - 1];
                $('#' + gridname).datagrid('getData').rows[index] = todown;
                $('#' + gridname).datagrid('getData').rows[index][sortname] = index + 1;
                $('#' + gridname).datagrid('getData').rows[index - 1] = toup;
                $('#' + gridname).datagrid('getData').rows[index - 1][sortname]=index;
                $('#' + gridname).datagrid('refreshRow', index);
                $('#' + gridname).datagrid('refreshRow', index - 1);
                $('#' + gridname).datagrid('uncheckRow', index);
                $('#' + gridname).datagrid('selectRow', index - 1);
            }
        } else if ("down" == type) {
            var rows = $('#' + gridname).datagrid('getRows').length;
            if (index != rows - 1) {
                var todown = $('#' + gridname).datagrid('getData').rows[index];
                var toup = $('#' + gridname).datagrid('getData').rows[index + 1];
                $('#' + gridname).datagrid('getData').rows[index + 1] = todown;
                $('#' + gridname).datagrid('getData').rows[index + 1][sortname] = index + 2;
                $('#' + gridname).datagrid('getData').rows[index] = toup;
                $('#' + gridname).datagrid('getData').rows[index][sortname] = index + 1;
                $('#' + gridname).datagrid('refreshRow', index);
                $('#' + gridname).datagrid('refreshRow', index + 1);
                $('#' + gridname).datagrid('uncheckRow', index);
                $('#' + gridname).datagrid('selectRow', index + 1);
            }
        }

    }

你可能感兴趣的:(jquery-easyui)