easyui datagrid 单元格编辑 即见即所得,MVC菜单维护,扫描增加
效果如图:

参见 EasyUI 官方 Demo 及文档
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
<table id="datagrid" class="easyui-datagrid" title="" style="width: 100%;"
    data-options="rownumbers:true,autoRowHeight:false,pagination:true,toolbar:'#tb',footer:'#ft',fit:true,
                pageSize:,singleSelect:true,collapsible:true,url:'@Url.Action("GetGridJSON")',method:'post',fixed:true,
                remoteSort:false,onClickCell: onClickCell,onAfterEdit:onAfterEdit,
                multiSort:true">
    <thead>
        <tr>
            <th data-options="field:'Id',checkbox:true"></th>
            <th data-options="field:'Url',editor:'text'">Url</th>
            <th data-options="field:'MenuNo',editor:'text'">MenuNo</th>
            <th data-options="field:'MenuLevel',editor:'text'">MenuLevel</th>
            <th data-options="field:'MenuName',editor:'text'">MenuName</th>
        </tr>
    </thead>
</table>
<div id="tb" style="padding: 2px 5px;">
    <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true">增加</a>
    @*<a href="#" class="easyui-linkbutton" iconcls="icon-edit" plain="true">修改</a>*@
    <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" plain="true">删除</a>
    <a href="#" class="easyui-linkbutton" iconcls="icon-xls" plain="true">导出Excel</a>
    <a href="#" class="easyui-linkbutton" iconcls="icon-scan" plain="true">扫描添加</a>
    <select onchange="$('#datagrid').datagrid({singleSelect:(this.value==0)})">
        <option value="">选中单行</option>
        <option value="">选中多行</option>
    </select>
    <input class="easyui-textbox" id="MenuNo" value="" name="MenuNo" data-options="prompt:'MenuNo:'" style="height: 22px; width: 120px">
    <input class="easyui-textbox" id="url" value="" name="url" data-options="prompt:'url:'" style="height: 22px; width: 120px">
    <input class="easyui-textbox" id="MenuName" value="" name="MenuName" data-options="prompt:'MenuName:'" style="height: 22px; width: 120px">
    <a href="#" class="easyui-linkbutton" onclick="doSearch()" iconcls="icon-search">查询</a>
    <div id="w" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true" style="padding: 10px;">
    </div>
</div>
<script>
    var UrlActionToExcel = "@Url.Action("ToExcel")";
    $(document).ready(function () {
        $("[iconcls='icon-scan']").click(function () {
            $.ajax({
                type: "GET",
                url: "scan",
                async: false, success: function (data) {
                    doSearch();
                    parent.showMsgTopCenter("提示", "已经生成" + data + "行记录");
                }
            });
        });
    });
</script>
<script type="text/javascript">
    $.extend($.fn.datagrid.methods, {
        editCell: function (jq, param) {
            return jq.each(function () {
                var opts = $(this).datagrid('options');
                var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));
                for (var i = ; i < fields.length; i++) {
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor1 = col.editor;
                    if (fields[i] != param.field) {
                        col.editor = null;
                    }
                }
                $(this).datagrid('beginEdit', param.index);
                for (var i = ; i < fields.length; i++) {
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor = col.editor1;
                }
            });
        }
    });
    var editIndex = undefined;
    function endEditing() {
        if (editIndex == undefined) { return true }
        if ($('#datagrid').datagrid('validateRow', editIndex)) {// 检测  数据是否发生 改变
            $('#datagrid').datagrid('endEdit', editIndex);// 触发 onAfterEdit  方法
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickCell(index, field, data) {
        if (endEditing()) {
            $('#datagrid').datagrid('selectRow', index)
                    .datagrid('editCell', { index: index, field: field, data: data });
            editIndex = index;
        }
    }
    function onAfterEdit(rowIndex, rowData, changes) {//  onAfterEdit 在  rowData 本行数据 ,changes 发生改变的数据
        for (change in changes) {
            var temp = {};
            temp[change] = changes[change];
            temp["Id"] = rowData.Id;
            temp["MenuLevel"] = rowData.MenuLevel; // 这是 int 类型 ,后台  只排除 string == null,所有要加上
            $.ajax({
                type: "POST", url: "updateCell", traditional: true, data: temp,//每次 只修改 一行数据中的 某一个字段
                async: false, dataType: "json", sunccess: function (data) {//dataType  没有限制
                       parent.showMsgTopCenter("提示", "已修改" + data + "行数据");
                }
            })
        }
    }
</script>
public void UpdateCell(Sys_Menu model)
{
ef_Help.ModifyWithOutproNames<Sys_Menu>(model);
Response.Write(db.SaveChanges());
Response.End();
}
public int Scan()
{
var My_Assembly = Assembly.GetExecutingAssembly();// 获得 当前 正在 运行 的程序集
My_Assembly.GetType().GetMethods();
string[] ReturnTyoes = { "ActionResult", "Int32", "String" };//只接收 返回值类型 为 这3中的方法。
var Models = db.Sys_Menu.ToList();// 菜单集合
List<string> UrlArr = new List<string>();// 扫描 Url 集合
foreach (Type type in My_Assembly.GetTypes())//遍历所有 类
{
if (type.Name.Contains("Controller") && type.FullName.Contains("Areas"))// 只扫描 Areas 下的 Controller 类
{
var FullName = type.FullName.Split('.');
var AreaName = FullName[];//获得区域名称
var ControllerName = FullName[].Substring(, FullName[].Length - "Controller".Length);//获得 Control 名称
foreach (var Method in type.GetMethods())//遍历 所有 方法
{
if (ReturnTyoes.Contains(Method.ReturnType.Name) && Method.DeclaringType.Name != "Object")// 排除 基类 Object ,及它的方法
{
var ActionNameAttribute = Method.GetCustomAttributes(typeof(ActionNameAttribute), false);
var MethodName = ActionNameAttribute.Length > ? ((ActionNameAttribute)Method.GetCustomAttributes(typeof(ActionNameAttribute), false)[]).Name : Method.Name;
var Url = string.Format("/{0}/{1}/{2}", AreaName, ControllerName, MethodName);//获得 真实 action (有ActionNameAttribute标记的 ) if (Models.Where(X => X.Url == Url).FirstOrDefault() == null && !UrlArr.Contains(Url))// 排除 已有的Url
{
UrlArr.Add(Url);
}
}
}
}
}
foreach (var url in UrlArr)
{
db.Sys_Menu.Add(new Sys_Menu()
{
MenuLevel = ,
MenuName = "未知",
MenuNo = "未知",
Url = url
});
} return db.SaveChanges();
}
easyui datagrid 单元格编辑 即见即所得,MVC菜单维护,扫描增加的更多相关文章
- EasyUI Datagrid 单元格编辑
		
3:对于单元格的编辑 $('#Units').datagrid({ pageNumber: 1, //url: "@ViewBag.Domain/Paper/GetQuestionUnit& ...
 - easyui datagrid 单元格编辑(cell editing)
		
demo中有row editing 项目中发现个cell editing,但是有bug,修改好了 主要实现功能:单击数据表格单元格,编辑单元格数据 js代码如下: $.extend($.fn.data ...
 - easyui datagrid 单元格 编辑时 事件 修改另一单元格
		
//datagrid 列数据 $('#acc').datagrid({ columns : [ [ { field : 'fee_lend', title : '收费A', width : 100, ...
 - easyui datagrid 单元格编辑  自动聚焦 、全选
		
$.extend($.fn.datagrid.methods, { editCell: function (jq, param) { return jq.each(function () { var ...
 - EasyUI datagrid单元格文本超出显示省略号,鼠标移动到单元格显示文本
		
nowrap : true; 是前提 $('#×××').datagrid({ nowrap : true,//设置为true,当数据长度超出列宽时将会自动截取 }); 省略号样式: <sty ...
 - easyui datagrid单元格实现溢出文本显示省略号的效果。
		
Css .datagrid-btable .datagrid-cell{padding:6px 4px;overflow: hidden;text-overflow:ellipsis;white-sp ...
 - easyui  datagrid 单元格加进度条(亲测可用)
		
{field: 'DataItemNum', title: '数据完整度', width: 100, formatter: function (v, r, i) { var p = (v / 27) ...
 - Datagrid扩展方法InitEditGrid{支持单元格编辑}
		
//-----------------------------------------------------------------/******************************** ...
 - Datagrid扩展方法onClickCell{easyui-datagrid-扩充-支持单元格编辑}
		
//-----------------------------------------------------------------/******************************** ...
 
随机推荐
- ORACLE—002:Create创作型
			
--用于工作的积累SQL ORACLE另外还有的类型.储过程.函数等的输入输入出. 以下看下创建. 使用方法 CREATE OR REPLACE TYPE 类型名称 AS OBJECT( 字段1 ...
 - 无需Visual Studio,5容易的 - 分为报告
			
总报告设计,例如RDLC.水晶报表等.,需要安装Visual Studio.由VS提供报表设计界面设计报告,由VS设计报告.NET非常方便开发者,.但对于非开发,安装4G一个VS.并且需要Licens ...
 - The C5 Generic Collection Library  for C# and CLI
			
The C5 Generic Collection Library for C# and CLI https://github.com/sestoft/C5/ The C5 Generic Colle ...
 - 第22题 Rotate List
			
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
 - ZOJ 3623 Battle Ships 简单DP
			
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3623 题意:给出N种可以建造的船和对方的塔生命值L,每种船给出建造时 ...
 - http报错之return error code:401 unauthorized
			
 http报错之return error code:401 unauthorized 依据HTTP返回码所表示的意思应该是未授权,没有输入账号和password,因此解决方法就直接在HTTP包里面 ...
 - 策略模式设计模式(Strategy)摘录
			
23种子GOF设计模式一般分为三类:创建模式.结构模型.行为模式. 创建模式抽象的实例.一个系统独立于怎样创建.组合和表示它的那些对象.一个类创建型模式使用继承改变被实例化的类,而一个对象创建型模式将 ...
 - 推荐他们认为有用Sublime Text3小工具
			
所有插件package control安装.一些国家的破解版sublime该插件是建立,安装自己的百度没有内置的方法,这里就不再重复 打开sublime.ctrl+shift+P,输入pis回车,稍等 ...
 - (一)IE8以下background不起作用
			
最近遇到了些小bug,在这里做个记录分享下.低版本的浏览器不支持新属性或者说对代码的解析方式不一样,导致最后解析出来的结果五花八门,各种浏览器之间的兼容的确是一个令开发人员头疼的事情,不过有时候换一个 ...
 - cocos2dx 3.x Value、Vector和Map意识
			
1. Value cocos2d::Value 这包括一个非常大的数字原生类型(int,float,double,bool,unsigned char,char* 和 std::string)外 加s ...