php中的datatables标题列问题

时间:2012-06-15 08:00:30

标签: php sorting datatables

我正在使用我的php脚本的datatables插件。我有一个8列的表。通过使用数据,我可以通过单击表列的标题对记录进行排序。现在我想限制这个排序功能只有6列,因为其中一列显示复选框,另一列显示图像。所以不需要对这两列进行排序。我如何限制这两列?我的代码如下:

<script type="text/javascript">
$(document).ready(function(){
  $('#example').dataTable( {
    "bProcessing": true,
    "sAjaxSource": "datatable-managedealdb.php",
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "oLanguage": {
      "sSearch": "Search :"
    }

  } );} );

</script>
<table class="form_table display dataTable" id="example" cellpadding="0" cellspacing="0">
  <thead>
  <?php $i = 1; ?>
  <tr >
    <th id="blankSpace">&nbsp;</th>
    <th class="sorting_asc">Deal No.</th>
    <th >Name</th>
    <th >Deals Description</th>
    <th >Start Date</th>
    <th >End Date</th>
    <th align="left">No. of Clicks</th>
    <th >Image</th>
    <th >Status</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td colspan="9" class="dataTables_empty">Loading data from server</td>
  </tr>
  </tbody>
</table>

并在datatable-managedealdb.php文件中:

...
while ( $aRow = mysql_fetch_array( $rResult ) )
{
  $deal_img = ($aRow['deal_thumb_img'] == '')?'no-pic.jpg':$_SESSION['busername'].'/'.$aRow['deal_thumb_img'];
  $row = array();
  $row[] = "<input type='radio' name='deal_check' id='smallBtn' value='".$aRow['deal_id']."' />";
  if($aRow['deal_no'] != ''){

    $row[] =$aRow['deal_no'];
  }
  if($aRow['deal_name'] != ''){
    $row[] = $aRow['deal_name'];
  }

  if($aRow['deal_desc'] != ''){
    $row[] = (strlen($aRow['deal_desc'])>100)?substr(wordwrap($aRow['deal_desc'],80,"<br />\n",TRUE),0,100)."...":wordwrap($aRow['deal_desc'],80,"<br />\n",TRUE);
  }
  if($aRow['start_deal_date'] != ''){
    $row[] = format_date(substr($aRow['start_deal_date'],0,10));
  }
  if($aRow['end_deal_date'] != ''){
    $row[] = format_date(substr($aRow['end_deal_date'],0,10));
  }
  if($aRow['deal_no_of_clicks'] != ''){
    $row[] = $aRow['deal_no_of_clicks'];
  }
  if($aRow['deal_thumb_img'] != ''){
    //$row[] = ($aRow['payment_status'] == 1)?"Paid":"Due";
    $row[] = "<img src='".DEAL_UPLOADING_PATH.$_SESSION['busername'].'/'.$aRow['deal_thumb_img']."' width='25' height='25' border='0' />";
  }
  else if($aRow['deal_thumb_img'] == ''){
    $row[] = "<img src='".DEAL_UPLOADING_PATH."no-pic.jpg' width='25' height='25' border='0' />";
  }

  if($aRow['deal_status'] == '0'){
    $row[] = '<img src="img/flag1.png" border="0" title="Disable"/>';
  }
  else if($aRow['deal_status'] == '1'){
    $row[] = '<img src="img/flag.png" border="0" title="Enable"/>';
  }


  $output['aaData'][] = $row;
}
...

请帮帮我。

1 个答案:

答案 0 :(得分:0)

有一个名为bSortable的设置 所以你可以尝试一下:

$('#example').dataTable({
  "bProcessing": true,
  "sAjaxSource": "datatable-managedealdb.php",
  "bJQueryUI": true,
  "sPaginationType": "full_numbers",
  "oLanguage": {
    "sSearch": "Search :"
  },
  "aoColumnDefs": [{ "bSortable": false, "aTargets": [7, 8] }]
  /*
  alternatively null for all first 6 columns, the other 2 are set to disabled:

  "aoColumns": [
    null, null, null, null, null, null,
    { "bSortable": false },
    { "bSortable": false },
  ]
  */
});