//cshtml代码
@{
ViewBag.Title = "角色管理";
}
@section scripts{
<script src="~/Content/js/role/role.js">
</script>
}
<table id="dg" class="easyui-datagrid" title="角色管理" style="width:700px;height:auto"
data-options="
iconCls:'icon-edit',
singleSelect:true,
toolbar:'#tb',
url:'/Role/GetRole',
method:'post',
onDblClickCell:onDbClickRow,
onClickCell:onClickRow
">
<thead>
<tr>
<th data-options="field:'BaseId',width:200" hidden="hidden"></th>
@*<th data-options="field:'Name',width:100,editor:{type:'text'}" >名称</th>*@
<th field="Name" width="150" editor="{type:'validatebox',options:{required:true}}">名称</th>
<th data-options="field:'Description',width:300" editor="text ">描述</th>
<th data-options="field:'Sequence',width:100" editor="text">排序</th>
</tr>
</thead>
</table>
<div id="tb" style="height:auto">
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">增加</a>
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="remove()">删除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()">保存</a>
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">取消</a>
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="setmenu()">设置角色菜单</a>
@*<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="getChanges()">GetChanges</a>*@
</div>
//js代码
var editIndex = undefined;
function endEditing() {
if (editIndex == undefined) { return true }
debugger;
if ($('#dg').datagrid('validateRow', editIndex)) {
$('#dg').datagrid('endEdit', editIndex);
editIndex = undefined;
return true;
} else {
return false;
}
}
function onClickRow(index) {
debugger;
var rows = $('#dg').datagrid('getChanges');
if (rows.length > 0) {
utils.message('error', '请先保存当前操作!');
return;
}
$('#dg').datagrid('endEdit', editIndex);
editIndex = index;
$('#dg').datagrid('selectRow', editIndex);
//$('#dg').datagrid('acceptChanges');
}
function onDbClickRow(index) { 双击进行编辑
debugger;
var rows = $('#dg').datagrid('getChanges');
if (rows.length > 0) {
utils.message('error', '请先保存当前操作!');
return;
}
$('#dg').datagrid('selectRow', index)
.datagrid('beginEdit', index);
}
function append() { //保存操作 保存到数据库
var rows = $('#dg').datagrid('getChanges');
if (endEditing()) {
if (rows.length > 0) {
utils.message('error', '请先保存当前操作!');
return;
}
}
if (endEditing()) {
$('#dg').datagrid('appendRow', { status: 'P' });
editIndex = $('#dg').datagrid('getRows').length - 1;
$('#dg').datagrid('selectRow', editIndex)
.datagrid('beginEdit', editIndex);
}
}
function remove() {
if (editIndex == undefined) { return }
debugger;
//var row = $('#dg').datagrid('getSelected');
var row = $('#dg').datagrid('getRows')[editIndex];
if (row.BaseId) {
utils.message('confirm', '确认要删除吗?', function (b) {
if (b) {
var row = $('#dg').datagrid('getSelected');
var roleid = row.BaseId;
$.ajax({
url: '/Role/DeleteRole',
data: { "id": roleid },
type: "POST",
success: function (data) {
if (data.Status) {
utils.message('success', '删除成功!');
$('#dg').datagrid('acceptChanges');
$('#dg').datagrid('reload');
}
}
});
debugger;
}
})
} else {
$('#dg').datagrid('cancelEdit', editIndex)
.datagrid('deleteRow', editIndex);
editIndex = undefined;
}
}
function accept() {
if (endEditing()) {
debugger;
var rows = $('#dg').datagrid('getChanges');
var _list = {};
if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) {
_list["roles[" + i + "].BaseId"] = rows[i].BaseId;
_list["roles[" + i + "].Name"] = rows[i].Name;
_list["roles[" + i + "].Description"] = rows[i].Description;
_list["roles[" + i + "].Sequence"] = rows[i].Sequence;
}
$.ajax({
url: '/Role/SaveRole',
// data: { "roles": _list },
data: _list,
dataType: "json",
type: "POST",
success: function (data) {
if (data.Status) {
utils.message('success', '保存成功!');
$('#dg').datagrid('reload');
}
}
});
}
}
}
function reject() {
$('#dg').datagrid('rejectChanges');
editIndex = undefined;
}
jqery easyui 利用datagrid增删该查后台权限
最新推荐文章于 2019-12-03 08:52:54 发布