根据字段更改DataTable上的文本

时间:2015-11-05 20:19:58

标签: jquery datatables

我正在使用jQuery DataTables。我有一个循环ListDependencies.pm的表行status,当它循环时,它将具有日期或为NULL。现在,如果它是NULL,那么它显示PROCESSING,如果它有一个日期,它显示COMPLETED与这个JS线

<td>#dateFormat(someprocessTable.Date_Complete, 'mm/dd/yyyy')#</td>

如果{ "data": "Date_Complete", "render": function(data){ return ((data) ? "COMPLETED" : "PROCESSING"); } }, 行说明其RMKS没有日期,则我需要弄清楚如何让它说EXEMPT而不是处理。如果Date_Complete的日期和Date_Complete是免税的话,那么它仍然应该说是已完成。这可以在JS方面做到吗?

HTML

Rmks

JS

<table id="processing1" class="table table-hover">
    <thead>
        <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
        <th><b>ITEM ID</b></th>
        <th style="display:none;"><b>DEALER ID</b></th>
        <th style="display:none;"><b>DATE RECEIVED</b></th>
        <th style="display:none;"><b>OP ID</b></th>
        <th><b>DUE DATE</b></th>
        <th><b>STATUS</b></th>
        <th style="display:none;"><b>LATE</b></th>
        <th style="display:none;"><b>CLOSED BY</b></th>
        <th style="display:none;"><b>RMKS</b></th>
        <th style="display:none;"><b>PROCESSING LOCATION</b></th>
        <th><b>QTY</b></th>

    </thead>
    <tbody>
   <cfoutput query="someprocessTable">                     
    <tr>
        <td class="details-control"></td>
        <td class="LAlign">#id#</td>
        <td style="display:none;">#someprocessTable.name#</td>
        <td style="display:none;">#dateFormat(someprocessTable.Date_Received, 'mm/dd/yyyy')#</td>
        <td style="display:none;">#getop_id(op_id)#</td>
        <td>#dateFormat(someprocessTable.Date_Due, 'mm/dd/yyyy')#</td>
        <td>#dateFormat(someprocessTable.Date_Complete, 'mm/dd/yyyy')#</td>
        <td style="display:none;">#Completed_Late#</td>
        <cfif len(Closed_by)>
        <td style="display:none;">#getClosed_by(Closed_by)#</td>
        <cfelse>
        <td style="display:none;">#Closed_by#</td>
        </cfif>
        <td style="display:none;">#Rmks#</td>
        <td style="display:none;">#Processing_Location#</td>
        <td class="CAlign">#Item_Count#</td>
    </tr>                      
   </cfoutput>
   </tbody>
</table>

enter image description here

此图片显示备注豁免所以它应该显示状态为EXEMPT而不是PROCESSING但是一旦Date_Complete中有一个日期,它应该显示为COMPLETED
enter image description here

不同的可能性:
function format ( d ) { return '<div class="slider">'+ 'Item ID: '+d.id+'<br>'+ 'Dealer: '+d.dealerID+'<br>'+ 'Date Received: '+d.Date_Received+'<br>'+ 'Checked In: '+d.op_id+'<br>'+ 'Date Due: '+d.Date_Due+'<br>'+ 'Date Complete: '+ ((d.Date_Complete) ? d.Date_Complete : 'N/A')+'<br>'+ 'Completed Late: '+ ((d.Completed_Late) ? d.Completed_Late : 'N/A')+'<br>'+ 'Completed By: '+ ((d.Closed_by) ? d.Closed_by : 'N/A')+'<br>'+ 'Remarks: '+ ((d.Rmks) ? d.Rmks : 'N/A')+'<br>'+ 'Location: '+d.Processing_Location+'<br>'+ 'Item Count: '+d.Item_Count+'<br>'+ '</div>'; } // Setup the page once it has loaded. $(document).ready(function() { var oTable = $('#processing1').DataTable( { "columns": [ { "class": "details-control", "orderable": false, "data": null, "defaultContent": "" }, { "data": "id" }, { "data": "dealerID" }, { "data": "Date_Received" }, { "data": "op_id" }, { "data": "Date_Due" }, { "data": "Date_Complete", "render": function(data){ return ((data) ? "COMPLETED" : "PROCESSING"); } }, { "data": "Completed_Late" }, { "data": "Closed_by" }, { "data": "Rmks" }, { "data": "Processing_Location" }, { "data": "Item_Count" } ], "order": [[1, 'asc']], "columnDefs": [ { "targets": [0,2,3,4,5,6,7,8,9,10,11], "searchable": false } ], "sDom": '<"row view-filter"<"col-sm-12"<"pull-left"l><"pull-right"f><"clearfix">>>t<"row view-pager"<"col-sm-12"<"text-center"ip>>>', select: { style: 'single' }, scrollY: 250, deferRender: true, scroller: true, //scrollCollapse: true, "aLengthMenu": [[25, 50, 75, -1], [25, 50, 75, "All"]], "iDisplayLength": 25, "oLanguage": { "sLengthMenu": "_MENU_ <label for='processing_length'><strong>records per page</strong></label>", "oPaginate": { "sPrevious": "«", "sNext": "»", } } }); 的日期和Date_Complete免除=已完成的日期 Rmks的日期和Date_Complete Null =已完成的日期 Rmks的空日期和Date_Complete免除= EXEMPT
Rmks的空日期和Date_Complete空=处理

1 个答案:

答案 0 :(得分:1)

如果函数被赋予render选项的值,则其中一个参数包含行数据。

使用以下代码包含来自其他列的条件数据:

"render": function(data, type, row, meta){
   if(data && (row['Rmks'] === 'Exempt' || !row['Rmks'])){
      data = "COMPLETED";
   } else if (!data && row['Rmks'] === 'Exempt'){
      data = "EXEMPT";
   } else if (!data && !row['Rmks']){
      data = "PROCESSING";
   } else {
      data = "";
   }

   return data;
}