本文主要是介绍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]);}}
这篇关于easyUI中控制datagrid 行上移 下移 置顶 置底的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!