小编Aly*_*cus的帖子

选择行时启用自定义按钮(默认情况下禁用)

我有一个数据表,其中显示了两个定义了两个自定义按钮的分支数据:添加和更新。它们在Javascript部分的顶部进行了初始化

var buttons;
var tblBranch;

$.fn.dataTable.ext.buttons.add = {
            className: 'button-add',
            text: "Add Branch",
            action: function (dt) {
                onBtnAddClicked()
            }
        };

$.fn.dataTable.ext.buttons.update = {
            className: 'button-update',
            text: "Update",
            action: function (dt) {
                onBtnUpdateClicked()
            }
        };
Run Code Online (Sandbox Code Playgroud)

我想在页面加载时禁用“编辑”按钮,并且仅在选中某行后才使其可单击。问题是,我正在使用自定义按钮,而在datatables.net上找不到有关如何根据条件启用/禁用它们的任何内容。到目前为止,我尝试过的是:

tblBranch = $("#tblBranches").DataTable({
        dom: 'Blfrtip',
        buttons: {
            buttons :[
                'add', 'update'
            ]
        }
        select: true;
})

$("#tblBranches tbody").on('click', 'tr', function () {
        if (tblBranch.row(this).hasClass('selected')) {
             $('button-update').removeClass("DTTT_disabled");
        }
        else {
             table.$('tr.selected').removeClass('selected');
             $('button-update').addClass("DTTT_disabled");
        }
});
Run Code Online (Sandbox Code Playgroud)

但是我不知道在页面加载时禁用“编辑”按钮的代码应该是什么样的,我一直在这里这里这里这里查看

感谢您的指导。

javascript jquery datatables tabletools datatables-1.10

5
推荐指数
1
解决办法
3665
查看次数

DataTables警告 - 请求第0行第0列的未知参数"0"

我正在使用jQuery DataTable来显示使用存储过程和Web服务从数据库中获取的数据.我可以使用Fiddler运行SP或服务,但是当填充DataTable时,我会在此处记录错误.在我的具体情况下,消息是:

"DataTables警告:table id = tblCashRecord - 第0行,第0列请求的未知参数'0'"

然后发生的是我的DataTable显示正确的行数,但所有单元格都是空的.

我很确定HTML表中的列数与我使用aoColumns(它的四个)推送的列数相同,但我可能错了.我知道有很多同样的问题被问过,但这个是唯一一个我发现有用的,可能是相关的,我也试过这个没有成功.

我的HTML表格:

<table id="tblCashRecord" class="table table-bordered">
    <thead>
        <tr>
            <th>Kiosk Name</th>
            <th>Service Type</th>
            <th>Transaction Timestamp</th>
            <th>Amount (RM)</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
    <tfoot>
        <tr>
            <th colspan="3" style="text-align: right">Total:</th>
            <th><span id="totalAmount" style="margin-left: -8px;"></span></th>
        </tr>
    </tfoot>
</table>
Run Code Online (Sandbox Code Playgroud)

我的Javascript:

$.ajax({
                        type: "POST",
                        url: "../Services/Report.svc/GetCashPaymentRecord/?s=" + session + "&r=" + reference,
                        data: "{\"kioskID\":" + JSON.stringify(kioskID) + "," + "\"startDate\": " + JSON.stringify(startDate) + "," + "\"endDate\":" + JSON.stringify(endDate) + "}",
                        contentType: …
Run Code Online (Sandbox Code Playgroud)

javascript c# jquery datatables

5
推荐指数
1
解决办法
2万
查看次数