jqery easyui 利用datagrid增删该查后台权限

//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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值