easyUI datagrid 行上移 下移 置顶 置底



//上移 function MoveUp() { var row = $("#Student_Table").datagrid('getSelected'); var index = $("#Student_Table").datagrid('getRowIndex', row); mysort(index, 'up', 'Student_Table'); } //下移 function MoveDown() { var row = $("#Student_Table").datagrid('getSelected'); var index = $("#Student_Table").datagrid('getRowIndex', row); mysort(index, 'down', 'Student_Table'); } function mysort(index, type, gridname) { 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 - 1] = toup; $('#' + gridname).datagrid('refreshRow', index); $('#' + gridname).datagrid('refreshRow', index - 1); $('#' + 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] = toup; $('#' + gridname).datagrid('refreshRow', index); $('#' + gridname).datagrid('refreshRow', index + 1); $('#' + gridname).datagrid('selectRow', index + 1); } } } function setTopOrBottom(isTop) { var rows = $('#dg').datagrid('getSelections'),newRows=JSON.parse(JSON.stringify(rows)); if (rows.length == 0) { alert('请选择要操作的数据行!'); return; } for (var i = rows.length - 1; i >= 0; i--) { $('#dg').datagrid('deleteRow', $('#dg').datagrid('getRowIndex', rows[i])); } for (var i = newRows.length - 1; i >= 0; i--) { if (isTop) $('#dg').datagrid('insertRow', { index: 0, row: newRows[i] }); else $('#dg').datagrid('appendRow', newRows[i]); } }

 

你可能感兴趣的:(Java)