データテーブル1.10を使用してテーブルを生成しています。私はサーバー側の処理を使用します。別の変数(ステータス)に応じて、テーブルの余分な列を表示または非表示にしたいとします。 datatable.netサーバーサイド処理で条件付きで列を表示/非表示にするにはどうすればよいですか? ここに私のコード(単純化)されていますdatatable.netサーバサイド処理で条件付きで列を表示/非表示にするにはどうすればいいですか?
$('#' + id).DataTable({
dom: "< <'col-md-4 col-sm-12 col-xs-12'f><'col-md-8 col-sm-12 col-xs-12'l><'col-md-12 col-sm-12 col-xs-12 no-padding't><'col-md-3 col-sm-12 col-xs-12'i><'col-md-9 col-sm-12 col-xs-12'p>>"
, responsive: true
, createdRow: function (row, data, dataIndex) { //this is used to add data- attribute to td element
$(row).find('td:eq(4)').attr('data-priority', data.Actions[0].action_priority);
}
, autoWidth: true //false
, scrollX: true
, pageResize: true
, serverSide: true
, processing: true
, pageLength: 100
, deferRender: true
, ajax: {
url: actionURL,
type: 'POST',
contentType: "application/json",
data: function (model) {
model.statusID = statusID ;
},
}
, columnDefs:
[
{
targets: 0,
createdCell: function (td, data, rowData, row, col) {
*//this is the part that does not work
if (incidentStatusID == 1) {
//here show column
visible:true;
}
else{
//hide column...
visible: false;
}
}
},*
{
targets: 3,
createdCell: function (td, data, rowData, row, col) { //this is used to add data- attribute to td element
$(td).attr('data-priority', data.Actions[0].action_priority);
}
}
]
は、たぶん私は列のcreatedRow
の同等、およびcreatedCell
を使用することができますか?私は1つを見つけることができませんでしたが。これをどうやって行うのですか?
https://datatables.net/examples/api/show_hide.htmlこのリンクを参照してください:ここで
は、コードのrelevent新しい作品です。 –ご意見ありがとうございます。リンクは直接私に解決策を提供しませんでしたが、別の方法で考えていました...テーブルの作成後に列を非表示にすることで、「ロード」しないでください。 – Sychal
何か試してみるのは良いことです。 –