禁用数据表行中的ADD按钮并启用它通过单击其他行JQUERY中的其他ADD按钮

时间:2015-06-05 14:45:20

标签: jquery datatables

创建DataTable的代码

var MCCntrctrTable = S$('#tblMCSelVndr').DataTable({
        "sPaginationType": "full_numbers",
        "aoColumns": [
                            { "sTitle": "Vendor ID", "mData": "VendorID", "sWidth": "19%" },
                            { "sTitle": "Contractor Legal Name", "mData": "CNTRCTR_NM", "sWidth": "40%" },
                            //{ "sTitle": "Work Type", "mData": "CNTRCT_WorkTyp", "sWidth": "20%" },
                            { "sTitle": "Address ", "mData": "ADDR", "sWidth": "40%" },
                            { "sTitle": "", "mData": "CNTROR_ADDR_ID", "sWidth": "1%" },
                            { "sTitle": " ", "mRender": function (data, type, full) { return '<button>ADD</button>' }, "sWidth": "10%", "sClass": "center" }
        ],
        "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
        "bSort": true,
        "aaSorting": [],
        "bStateSave": true,
        "data": data,
        "bJQueryUI": true,
        "bAutoWidth": false,
        "columnDefs": [
       {
           "targets": [3],
           "visible": false
       }, ]

    });

点击行中的按钮时调用

S$('#tblMCSelVndr tbody').on('click', 'button', function (e) {
        debugger;
        var data = MCCntrctrTable.row(S$(this).parents('tr')).data();
        //MCCntrctrTable.eq(0).attr('disabled')
        newCNTRList = [];
        if (data) {
            var cntrctrToAdd = {
                CNTRCNTRCTRID: '',
                CntrctrAddID: data.CNTROR_ADDR_ID,
                VedorID: data.VendorID,
                LegalName: data.CNTRCTR_NM,
                CntrctrAddr: data.ADDR,
                ProgID: data.ProgID,
                CatID: data.CLCat_ID,
                SelMethod: S$("#SelectionMethod").val(),
                SelMethodName: S$("#SelectionMethod  option:selected").text()
            }

            debugger;

            newCNTRList.push(cntrctrToAdd);



        }

        //remove contractor from dataTable
        S$(this).attr('disabled', 'disabled');
    });

当我第一次单击表格行中的“添加”按钮时,该特定行的“添加”按钮将被禁用。 现在,如果我在其他行中单击其他添加,则应启用先前禁用的按钮。为此,我必须找到表中禁用的按钮。 我尝试了几种可能性,例如

S$('#tblMCSelVndr tbody').eq(0).attr('disabled')
S$('#tblMCSelVndr tbody').find('tr td disabled')

他们都没有工作!

1 个答案:

答案 0 :(得分:0)

您可以使用:disabled伪选择器。要删除disabled行为,您可以使用.prop()

S$('#tblMCSelVndr').find('button:disabled').prop('disabled', false);