Qualcuno ha idea su dove sbaglio?
Ho dato uno sguardo a degli esempi su questo sito http://www.datatables.net/ ma senza gorsso successo.
Posto anche la pagina php:
codice:
function ajax_show_all_news_table(){
/* Paging */
$sLimit = "LIMIT ".$this->input->post('iDisplayStart').",".$this->input->post('iDisplayLength');
/* Ordering */
$sOrder = "ORDER BY ";
for ( $i=0 ; $i<$this->input->post('iSortingCols') ; $i++ ){
switch($this->input->post('iSortCol_'.$i)){
case 3:$sOrder .= 'titolo '.$this->input->post('sSortDir_'.$i) .',';break;
case 4:$sOrder .= 'create_date '.$this->input->post('sSortDir_'.$i) .',';break;
case 5:$sOrder .= 'created_by '.$this->input->post('sSortDir_'.$i) .',';break;
default:$sOrder .= 'id '.$this->input->post('sSortDir_'.$i) .',';break;
}
}
$sOrder = substr_replace( $sOrder, "", -1 );
$sWhere = "";
if($this->input->post('sSearch') || $this->input->post('filter_active_news') || $this->input->post('filter_not_active_news')){
$sWhere = "WHERE ";
if ($this->input->post('sSearch')){
$sWhere .= "(id LIKE '%".$this->input->post('sSearch')."%' OR ".
"titolo LIKE '%".$this->input->post('sSearch')."%' OR ".
"create_date LIKE '%".$this->input->post('sSearch')."%' OR ".
"created_by LIKE '%".$this->input->post('sSearch')."%') ";
if($this->input->post('filter_active_news') || $this->input->post('filter_not_active_news')){
$sWhere .= " AND";
}
}
if($this->input->post('filter_active_news')){
$sWhere .= " attivo = 1 AND";
}
if($this->input->post('filter_not_active_news')){
$sWhere .= " attivo = 0 AND";
}
if($this->input->post('filter_active_news') || $this->input->post('filter_not_active_news')){
$sWhere = substr_replace( $sWhere, "", -3 );
}
}
$sQuery = "SELECT SQL_CALC_FOUND_ROWS id, titolo, desc_breve, testo, tag_news, attivo, create_date, created_by FROM news $sWhere $sOrder $sLimit";
echo $query = $this->db->query($sQuery)->result();
echo $sQuery = "SELECT FOUND_ROWS()";
$rResultFilterTotal = $this->db->query($sQuery)->first_row('array');
$iFilteredTotal = $rResultFilterTotal["FOUND_ROWS()"];
$sQuery = "SELECT COUNT(id) FROM news";
$rResultTotal = $this->db->query($sQuery)->first_row('array');
$iTotal = $rResultTotal["COUNT(id)"];
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($this->input->post('sEcho')).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
foreach ($query as $aRow){
$sOutput .= "[";
$sOutput .= '"'.addslashes('<span alt="" class="ui-icon ui-icon-plus"></span>').'",';
$sOutput .= '"'.addslashes('<input type="checkbox" />').'",';
$sOutput .= '"'.addslashes($aRow->id).'",';
$sOutput .= '"'.addslashes($aRow->titolo).'",';
$sOutput .= '"'.addslashes($aRow->created_by).'",';
$sOutput .= '"'.addslashes($aRow->create_date).'",';
$sOutput .= '"'.addslashes('<span class="ui-icon ui-icon-pencil" ></span>'.(($aRow->attivo == '1')?'<span class="ui-icon ui-icon-locked"></span>':'<span class="ui-icon ui-icon-unlocked"></span>').'<span class="ui-icon ui-icon-close"></span>').'",';
$sOutput .= '"'.addslashes($aRow->testo).'",';
$sOutput .= '"'.addslashes($aRow->tag_news).'",';
$sOutput .= '"'.addslashes($aRow->attivo).'",';
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
echo $sOutput;
return;
}
la tabella è news ed i campi sono:
id - titolo - desc_breve - testo - tag_news - attivo - create_date - created_by -
Ripeto almeno tramite firebugs non ci sono errori nel codice. La richiesta la fa e c'è un array risultato con 12 righe. Quelle che ho inserito nella tabella.
Ciao e grazie