当前位置: 动力学知识库 > 问答 > 编程问答 >

Converting jQuery Datatables to server-side php

问题描述:

From the outset - I am not an incredibly proficient php developer, so this is likely an easy problem to solve for some of you. That said, I am learning and do appreciate any insight as to "why" something does/doesn't work. I have previously reached out in the Datatables forums and tried many things on my own with no luck.

Here's the issue:

I've been doing this client-side successfully and been getting all the formatting correct. I am struggling to convert into server side using the script here - http://datatables.net/development/server-side/php_mysql

The data is coming in just fine, it is the formatting of different columns I am struggling with. Here is one example - I have a certain column that looks like this using client-side:

<td>

<div class="text-center">

<?php

if( is_null($row["FIELD1"]))

{echo "<div class=\"label label-inverse\">Not Started</div><div class=\"progress progress-warning slim\"><div class=\"bar\" style=\"width: 15%\"></div></div>";}

elseif( is_null($row["Final"]) && ($row["Status"]==='1') && is_null($row["Create"]))

{echo "<div class=\"label label-info\">In Progress</div><div class=\"progress progress-info slim\"><div class=\"bar\" style=\"width: 30%\"></div></div>";}

elseif( is_null($row["Final"]) && ($row["Status"]==='0') && ($row["MAP"]==='1') && is_null($row["Create"]))

{echo "<div class=\"label label-info\">In Progress</div><div class=\"progress progress-info slim\"><div class=\"bar\" style=\"width: 20%\"></div></div>";}

elseif( is_null($row["Final"]) && ($row["Status"]==='0') && ($row["VAP"]==='1') && is_null($row["Create"]))

{echo "<div class=\"label label-info\">In Progress</div><div class=\"progress progress-info slim\"><div class=\"bar\" style=\"width: 25%\"></div></div>";}

elseif( is_null($row["Final"]) && ($row["Status"]==='0') && ($row["LAP"]==='1') && is_null($row["Create"]))

{echo "<div class=\"label label-info\">In Progress</div><div class=\"progress progress-info slim\"><div class=\"bar\" style=\"width: 30%\"></div></div>";}

elseif( is_null($row["Final"]) && isset($row["Create"]) && is_null($row["Synch"]))

{echo "<div class=\"label label-info\">In Progress</div><div class=\"progress progress-info slim\"><div class=\"bar\" style=\"width: 45%\"></div></div>";}

elseif( is_null($row["Final"]) && isset($row["Synch"]) && is_null($row["Config"]))

{echo "<div class=\"label label-info\">In Progress</div><div class=\"progress progress-info slim\"><div class=\"bar\" style=\"width: 60%\"></div></div>";}

elseif( is_null($row["Final"]) && isset($row["Config"]) && is_null($row["AllSet"]))

{echo "<div class=\"label label-info\">In Progress</div><div class=\"progress progress-info slim\"><div class=\"bar\" style=\"width: 75%\"></div></div>";}

elseif( is_null($row["Final"]) && isset($row["AllSet"]))

{echo "<div class=\"label label-info\">In Progress</div><div class=\"progress progress-info slim\"><div class=\"bar\" style=\"width: 90%\"></div></div>";}

else

{echo "<div class=\"label label-success\">Completed</div><div>in ";} {echo($row["diff"]);} {echo "</div>";}

?>

</div>

</td>

I just can't figure out how to get that "Translated" to the format outlined here:

if ( $aColumns[$i] == "version" )

{

/* Special output formatting for 'version' column */

$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];

}

Simpler ones like this (formatting the date and changing the display of 0 or 1 to yes/no) I have been able to figure out:

<td><div class="text-center"><?php echo date("m/d/Y H:i A", strtotime($row["SDate"]));?></div></td>

<td>

<div class="text-center">

<?php if( is_null($row["Status"])){echo "<div class=\"label label-warning\">Checking...</div>";}else{echo ($row["Status"] ? 'yes': 'no');}?>

</div>

</td>

as it "Translates" to:

if ( $aColumns[$i] == "SDate" )

{

$row[] = date("m/d/Y H:i A", strtotime(($aRow[ $aColumns[$i] ])));

}

else if ( $aColumns[$i] == "Status" )

{

$row[] = ($aRow[ $aColumns[$i] ]) ? 'yes' : 'no';

}

But I'm having trouble getting things like all those extra conditionals working. Any guidance is appreciated.

UPDATE:

apparently my example is too complicated & misses the point. Here is what may be an easier example:

Depending on the status of the column "Exempt", I want to display "Checking" if it is null, and either yes or no if it is 1 or 0. Currently, the functioning client-side code looks like this:

 <td>

<div>

<?php

if( is_null($row["Exempt"]))

{echo "<div class=\"label label-warning\">Checking...</div>";}

else

{echo ($row["Exempt"] ? 'yes': 'no');}

?>

</div>

</td>

BUT, I can't get it to format correctly when using the style/formatting shown in this script http://datatables.net/development/server-side/php_mysql (also shown above). So, how do I fill in the following for that?

 if ( $aColumns[$i] == "Exempt" )

{

$row[]= //?????I can't get this part to work correctly

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: