c# - Icheck 样式未应用于数据表中的 ajax 数据绑定(bind)

标签 c# css ajax datatables icheck

我在我的 Web 应用程序中使用 iCheck 插件和 datatable.js

我使用 ajax 请求对该表进行数据绑定(bind)。

enter image description here

请看下面我的代码。

HTML

<table id="tblCountry" class="table table-striped table-bordered table-hover table-highlight table-checkable"
                        data-display-rows="10"
                        data-info="true"
                        data-search="true"
                        data-paginate="true"                            >
                        <thead>
                            <tr>
                                <th class="checkbox-column" style="min-width: 50px;">
                                    <input id="thCheckBox" type="checkbox" class="icheck-input" />
                                </th>
                                <th>Id</th>
                                <th style="min-width: 100px;">Country</th>
                            </tr>
                        </thead>
                    </table>

脚本

    ajaxUrl = '@Url.Action("GetTestCountryList", "Invoice")';

    dtTable = $("#tblCountry").dataTable({
        sAjaxSource: ajaxUrl,
        aoColumns: [
            {
                "sClass": "checkbox-column",
                bSortable: false,
                "mRender": function (data, type, full) {
                    return '<input type="checkbox" onclick="check(this)" class="icheck-input">';
                }
            },
            { sTitle: "Id", bSortable: false, bVisible: false, },
            { sTitle: "Name", bSortable: true, },
        ],
    });

来源

    public ActionResult GetTestCountryList()
    {

        List<Country> lstCountry = new List<Country>();

        lstCountry.Add(new Country { Id = 1, Name = "India" });
        lstCountry.Add(new Country { Id = 2, Name = "USA" });
        lstCountry.Add(new Country { Id = 3, Name = "France" });
        lstCountry.Add(new Country { Id = 4, Name = "Germiny" });
        lstCountry.Add(new Country { Id = 5, Name = "Britan" });

        return Json(new
        {
            aaData = lstCountry.Select(e => new string[]
            {
                "",
                e.Id.ToString(),
                e.Name
            }).ToArray()
        }, JsonRequestBehavior.AllowGet);
    }

我的问题是复选框样式仅应用于标题,未应用于行。我的代码有什么错误吗?

最佳答案

您需要从数据表 DrawCallBack 调用 icheck - 我有同样的问题...

$('.ajax-datatable').dataTable({
    responsive: false,
    order: [],
    sPaginationType: "simple_numbers",
    bJQueryUI: true,
    bProcessing: false,
    bServerSide: true,
    bStateSave: true,
    sAjaxSource: $('.ajax-datatable').data('source'),
    "columnDefs": [
        { "orderable": false, "targets":[$('.ajax-datatable').data('targets')]}
    ],

    "fnPreDrawCallback": function() {
        $.blockUI({ message: '<img src="<%= asset_path 'ajax-loader.gif'%>" />',css: { backgroundColor: 'none', border: '0px'} });
        return true;
    },
    "fnDrawCallback": function() {
        $.unblockUI();
        icheck();
    }
});

关于c# - Icheck 样式未应用于数据表中的 ajax 数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27752077/

相关文章:

html - CSS 过渡 : chained transforms start simultaneously

jquery - 修改 DOM 后提交按钮变得无响应

JavaScript 代码未正确检查 ajax 请求

c# - 通过 C# 运行 GCC 时从命令行获取 GCC 的输出

c# - 正则表达式解析 C# 源代码以查找所有字符串

c# - 使用表单例份验证调用 WCF 服务时避免重定向

jquery - 在 AJAX 请求期间显示/隐藏不起作用

c# - 在 IronPython 中使用 C# 代码

CSS 边框不会显示在空行上

javascript - jQuery DatePicker 未在自定义样式表中突出显示