2016-11-04 15 views
1

jquery datatableで選択した行の背景色を自分のcssクラスを使用して変更しようとしていますが、チェックボックスの目盛りは表示されません。jquery datatable - select.classNameの値を期待通りに適用しない

以下のコードからclassName: 'selected-row'を削除すると、すべて正常に動作しますが、色は必要ありません。

フィドラー:https://jsfiddle.net/8f63kmeo/12/

HTML:

<table id="CustomFilterOnTop" class="table table-bordered table-condensed" width="100%"></table> 

JS

var Report4Component = (function() { 
    function Report4Component() { 
     //contorls 
     this.customFilterOnTopControl = "CustomFilterOnTop"; //table id 
     //data table object 
     this.customFilterOnTopGrid = null; 
     //variables 
     this.result = null; 
    } 
    Report4Component.prototype.ShowGrid = function() { 
     var instance = this;  

     //create the datatable object 
     instance.customFilterOnTopGrid = $('#' + instance.customFilterOnTopControl).DataTable({ 
      columns: [ 
        { title: "<input name='SelectOrDeselect' value='1' id='ChkBoxSelectAllOrDeselect' type='checkbox'/>" }, 
       { data: "Description", title: "Desc" }, 
       { data: "Status", title: "Status" }, 
       { data: "Count", title: "Count" } 
      ], 
      "paging": true, 
      scrollCollapse: true, 
      "scrollX": true, 
      scrollY: "300px", 
      deferRender: true, 
      scroller: true, 
      dom: '<"top"Bf<"clear">>rt <"bottom"<"Notes">i<"clear">>', 
      buttons: [ 
       { 
        text: 'Load All', 
        action: function (e, dt, node, config) { 
         instance.ShowData(10000); 
        } 
       } 
      ],    
      columnDefs: [{ 
        orderable: false, 
        className: 'select-checkbox text-center', 
        targets: 0, 
        render: function (data, type, row) { 
         return ''; 
        } 
       }], 
      select: { 
       style: 'multi', 
       selector: 'td:first-child', 
       className: 'selected-row' 
      } 
     });   
    }; 

    Report4Component.prototype.ShowData = function (limit) { 
     if (limit === void 0) { limit = 100; } 
     var instance = this; 
     instance.customFilterOnTopGrid.clear(); //latest api function 
     instance.result = instance.GetData(limit); 
     instance.customFilterOnTopGrid.rows.add(instance.result.RecordList); 
     instance.customFilterOnTopGrid.draw(); 
    }; 
    Report4Component.prototype.GetData = function (limit) { 
     //structure of the response from controller method 
     var resultObj = {}; 
     resultObj.Total = 0; 
     resultObj.RecordList = []; 
     for (var i = 1; i <= limit; i++) { 
      resultObj.Total += i; 
      var record = {}; 
      record.Description = "This is a test description of record " + i; 
      record.Status = ["A", "B", "C", "D"][Math.floor(Math.random() * 4)] + 'name text ' + i; 
      record.Count = i; 
      resultObj.RecordList.push(record); 
     } 
     return resultObj; 
    }; 
    return Report4Component; 
}()); 
$(function() { 
    var report4Component = new Report4Component(); 
    report4Component.ShowGrid(); 
    report4Component.ShowData(); 
}); 
function StopPropagation(evt) { 
    if (evt.stopPropagation !== undefined) { 
     evt.stopPropagation(); 
    } 
    else { 
     evt.cancelBubble = true; 
    } 
} 

問題:

enter image description here

ご意見、ご協力をよろしくお願いいたします。

答えて

1

チェックボックスのチックなどを設定するクラスselectedです。別のクラスを使用すると、selectedクラスは追加されなくなりました。

は、あなただけの代わりに、これらのクラスの両方を追加することができ、そしてそれははい、それは問題を解決し

select: { 
    style: 'multi', 
    selector: 'td:first-child', 
    className: 'selected-row selected' 
} 

FIDDLE

+0

動作するはずです。ありがとうございました :) –

関連する問題