jQuery Datatables / CF变量问题

时间:2015-10-22 14:08:14

标签: jquery coldfusion datatables

我正在使用jQuery DataTables和Coldfusion以及数据库的SQL。如果PROCESSING中没有Date_CompleteCOMPLETED的日期,我试图想办法让我的状态字段显示Date_CompleteCOMPLETED我在HTML CF端使用IF语句执行此操作。

但是,当我尝试在JS中调用它时,它在该列中发布了PROCESSINGDate Complete: COMPLETED,因为它没有提供日期,而是现在提供该术语。

在下图中,您会看到<table id="processing" class="table table-hover"> <thead> <th></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="processTable"> <tr> <td class="details-control"></td> <td class="LAlign">#id#</td> <td style="display:none;">#processTable.name#</td> <td style="display:none;">#dateFormat(processTable.Date_Received, 'mm/dd/yyyy')#</td> <td style="display:none;">#op_id#</td> <td>#dateFormat(processTable.Date_Due, 'mm/dd/yyyy')#</td> <cfif #Date_Complete# EQ ""> <td>PROCESSING</td> <cfelse> <td>COMPLETED</td> </cfif> <td style="display:none;">#Completed_Late#</td> <td style="display:none;">#Closed_by#</td> <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

数据库表 enter image description here

HTML

function format ( d ) {

    return '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+'<br>'+
           'Completed Late: '+d.Completed_Late+'<br>'+
           'Completed By: '+d.Closed_by+'<br>'+
           'Remarks: '+d.Rmks+'<br>'+
           'Location: '+d.Processing_Location+'<br>'+
           'Item Count: '+d.Item_Count+'<br>';
    }
// Setup the page once it has loaded.
$(document).ready(function() {

    var oTable = $('#processing').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" },
            { "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,
        /*"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": "»",
            }
        }
    });

JS

<cffunction name="displayTable" access="public" returntype="query">
    <cfset var processTable = ''>
    <cfquery name="processTable">
        SELECT *
        FROM dbo.Dealer_Track_Work, dbo.Dealer_Track_Dealers
        WHERE dbo.Dealer_Track_Work.dealerID = dbo.Dealer_Track_Dealers.id      
    </cfquery>
    <cfreturn processTable>
</cffunction>

CFC

{{1}}

2 个答案:

答案 0 :(得分:2)

  • 替换此HTML代码:

    <cfif #Date_Complete# EQ "">
    <td>PROCESSING</td>
    <cfelse>
    <td>COMPLETED</td>
    </cfif>
    

    <td>#DateFormat(Date_Complete,"mm/dd/yyyy")#</td>
    
  • 替换此JavaScript代码

    { "data": "Date_Complete" },
    

    { 
        "data": "Date_Complete",
        "render": function(data, type, full, meta){
           return ((data) ? "COMPLETED" : "PROCESSING");
        }
    },
    

答案 1 :(得分:2)

评论太长

也许我没跟着你?它看起来像&#34;已完成&#34;文本来自您的HTML输出代码。具体在这里:

<cfoutput query="processTable">                     
 <tr>
     <td class="details-control"></td>
     <td class="LAlign">#id#</td>
     <td style="display:none;">#processTable.name#</td>
     <td style="display:none;">#dateFormat(processTable.Date_Received, 'mm/dd/yyyy')#</td>
     <td style="display:none;">#op_id#</td>
     <td>#dateFormat(processTable.Date_Due, 'mm/dd/yyyy')#</td>
     <cfif #Date_Complete# EQ "">
     <td>PROCESSING</td>
     <cfelse>
     <td>COMPLETED</td>
     </cfif>
     <td style="display:none;">#Completed_Late#</td>
     <td style="display:none;">#Closed_by#</td>
     <td style="display:none;">#Rmks#</td>
     <td style="display:none;">#Processing_Location#</td>
     <td class="CAlign">#Item_Count#</td>
 </tr>                           
</cfoutput>

因此,您应该能够相应地更改逻辑以显示实际日期。 (注意,您不需要cfif语句中的哈希标记。)

     <cfif Date_Complete EQ "">
         <td>PROCESSING</td>
     <cfelse>
         <td>#DateFormat(Date_Complete,"mm/dd/yyyy")#</td>
     </cfif>

或类似的东西取决于所需的格式。