zoukankan      html  css  js  c++  java
  • 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; } }
    用对方法才有效率,做对事情才有效果
    “麻烦”是自己“处理”不当的结果
    “困难”是自己“学习”不够的反射

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

  • 相关阅读:
    Vue2 组件注册
    Vue2 CSS 过渡
    Vue2 过滤器
    Vue2 路由
    网页一次滚动一屏幕效果
    JavaScript作用域-声明提升(个人总结)
    JS函数作用域提升
    如何以计算机的方式去思考
    常用Git命令总结
    关于RBAC(Role-Base Access Control)的理解(转)
  • 原文地址:https://www.cnblogs.com/ly7454/p/2989741.html
Copyright © 2011-2022 走看看