0

我正在为我的 php 脚本使用数据表插件。我有一个有 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;
}
...

请帮我。

4

1 回答 1

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 },
  ]
  */
});
于 2012-06-15T09:00:44.817 回答