• easyui datagrid 自定义列checkbox


    单击行选中checkbox,取消则取消checkbox。可根据条件,是否选中checkbox。

    $(function(){
        $('#dg').datagrid({ 
            title:'Load Data',   
            url:'/Customer2/GetCustomerList',
            pagination:true,
            rownumbers:true,
            fitColumns:true, 
            idField:'CustomerId',
            columns:[[ 
            {field:'CustomerId',title:'<input type="checkbox" id="ck_all" />',100,formatter: function(value,row,index){
                return row.FirstName == "ly3" ? '<input type="checkbox" disabled="disabled" name="ckId" />'
                :'<input type="checkbox" name="ckId" value="'+value+'" />';
            }}, 
            {field:'FirstName',title:'FirstName',100}, 
            {field:'LastName',title:'LastName',100,align:'center'} 
            ]],
            onLoadSuccess:function(){
                $("#ck_all").click(function(){
                    if($(this).attr("checked"))
                    {
                        var chks = $("input[name='ckId']");
                        for(var i=0;i<chks.length;i++)
                        {
                            var chkobj = $(chks[i])
                            if(!chkobj.attr("disabled"))
                            {
                                chkobj.attr("checked",true);
                            }
                            else
                            {
                               chkobj.parent().parent().parent().css({"background-color":"White"})
                            }
                        }
                    }
                    else
                    {
                        $("input[name='ckId']").attr("checked",false);
                    }
                })
            },
            onSelect:function(rowIndex, rowData){
                if(rowData.FirstName != "ly3")
                {
                    $("input[value='"+rowData.CustomerId+"']").attr("checked",true);
                }
            },
            onUnselect:function(rowIndex, rowData){
                $("input[value='"+rowData.CustomerId+"']").attr("checked",false);
            }  
    
        });   
    })

    html:

    <head>
        <title>@ViewBag.Title</title>
        <link href="@Url.Content("~/Scripts/easyui3.2/themes/default/easyui.css")" rel="stylesheet" type="text/css" />
        <link href="@Url.Content("~/Scripts/easyui3.2/themes/icon.css")" rel="stylesheet" type="text/css" />
        <script src="@Url.Content("~/Scripts/easyui3.2/jquery-1.8.0.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/easyui3.2/jquery.easyui.min.js")" type="text/javascript"></script>
    </head>
    <body>
    <table id="dg"></table>

    c#:

     
    public JsonResult GetCustomerList(int page, int rows)
            {
                return Json(new { total = CustomerBus.GetListPagesCount(), rows = CustomerBus.GetListPage(page, rows) });
            }
    /// <summary>
            /// 分页
            /// </summary>
            /// <param name="pageIndex"></param>
            /// <param name="pageSize"></param>
            /// <returns></returns>
            public static IList<Customer> GetListPage(int pageIndex, int pageSize)
            {
                StringBuilder sb = new StringBuilder();
                using (var session = Sessions.GetSession())
                using (var tx = session.BeginTransaction())
                {
                    var p = session.QueryOver<Customer>()
                        .OrderBy(c => c.CustomerId).Asc
                        .Skip((pageIndex - 1) * pageSize)
                        .Take(pageSize)
                        .List();
                    tx.Commit();
                    foreach (var item in p)
                    {
                        item.Orders = null;
                    }
                    return p;
                }
            }
            /// <summary>
            /// 
            /// </summary>
            /// <returns></returns>
            public static int GetListPagesCount()
            {
                using (var session = Sessions.GetSession())
                using (var tx = session.BeginTransaction())
                {
                    var p = session.QueryOver<Customer>()
                        .RowCount();
              tx.Commit();
    return p; } }
    用对方法才有效率,做对事情才有效果
    “麻烦”是自己“处理”不当的结果
    “困难”是自己“学习”不够的反射

    “挫折”是自己“努力”不足的代价

  • 相关阅读:
    ERRORCODE=4228, SQLSTATE=null
    DB2和Oracle中唯一约束和唯一索引对比
    SW 3D 样条曲线
    SW 快速操作
    spring依赖注入的方式(一)
    Oracle Connect By的用法
    转:min(x,y)高效算法
    【转】QQ盗号核心编程
    转:理解并解决GBK转UTF8奇数中文乱码
    Oracle数据库的导入和导出命令
  • 原文地址:https://www.cnblogs.com/ly7454/p/2989741.html
Copyright © 2020-2023  润新知