2011-06-06 5 views
0

codeigniterコントローラからjqueryデータテーブルを使ってデータテーブルを表示しています。私が知りたいのは、データテーブル内の値をコントローラに戻して、それらの値を使ってDBから新しいレコードを取得し、ページに再度ロードすることです。データテーブルからコードシニターにデータを返す

私の現在のコードは

私は、選択ボックスのいずれかに最小最大値を選択すると、今ではに送信されなければならない
$(function(){ 
    $('#tableChart').dataTable({ 
     // -------Function for formatting the table data elements------- 
     "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 


       $.each(aData, function (i, elem){      
        $('td:eq('+i+')', nRow).html('<b><font color="#40A913">'+aData[i]+'</font></b>'); 
       }) 
       return nRow; 
     }, 



      "bAutoWidth": false, 
      "bProcessing": true, 
      "bLengthChange": false, // Remove the show list drop down button 
      "bInfo": false,   // Remove info part under the table 
      "bFilter" : false,  // Remove search box 
      "bDestroy": true,   // Remove table & recreate table 

      "bServerSide": false, 

      "sAjaxSource": "<?php echo base_url(); ?>index.php/print_db_table/get_print_db_table/<?php echo $table_name; ?>", 

    });   
}); 

<div class="container"> 
    <div class="holderForTableChart"> 
     <table width ="100%" cellpadding="5" cellspacing="0" class="display" id="tableChart"> 
      <thead> 
       <tr id="tableHeadder" > 
        <?php 
         foreach($table_header as $item): 
          $header = $item->name; 
          echo '<th>'.$header.'</th>' ; 
         endforeach; 
        ?>            
       </tr> 
       <tr> 
       <td></td> 
       <td> 
       <select id=""></select> 
       <select id=""></select> 
       </td> 
       <td> 
       <select id=""></select> 
       <select id=""></select> 
       </td> 
       <td> 
       <select id=""></select> 
       <select id=""></select> 
       </td> 
       <td> 
       <select id=""></select> 
       <select id=""></select> 
       </td> 
       </tr> 
      </thead> 
      <tbody> 
       <tr> 
        <td colspan="6" class="dataTables_empty">Loading data from server</td> 
       </tr> 
      </tbody> 
     </table>  
    </div> 
</div> 

です私はモデルにそれらを送信し、それらを収集し、ビューでそれらを再ロードすることができますコントローラ

答えて

1

humm ...この選択ボックスにidが#min_max_valueとして設定されているとします。 JavaScriptコードは以下のコードのようになります。 このコードはajaxを再呼び出しし、テーブルを再描画します。 CodeIgniterのコントローラで uが http://www.datatables.net/usage/callbacks

var oTable = ''; 
$(function(){ 
    oTable = $('#tableChart').dataTable({ 
     // -------Function for formatting the table data elements------- 
     'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
       $.each(aData, function (i, elem){      
        $('td:eq('+i+')', nRow).html('<b><font color='#40A913'>'+aData[i]+'</font></b>'); 
       }) 
       return nRow; 
     }, 
      'bAutoWidth': false, 
      'bProcessing': true, 
      'bLengthChange': false, // Remove the show list drop down button 
      'bInfo': false,   // Remove info part under the table 
      'bFilter' : false,  // Remove search box 
      'bDestroy': true,  // Remove table & recreate table 
      'bServerSide': false, 
      'sAjaxSource': '<?php echo base_url(); ?>index.php/print_db_table/get_print_db_table/<?php echo $table_name; ?>', 

      'fnServerData': function (url, data, callback) { 
       // Add new data 
       data.push({'name':'min_max_value', 'value':$('#min_max_value').val()}); 
       $.ajax({ 
        'url': url, 
        'data': data, 
        'type': 'POST', 
        'success': callback, 
        'dataType': 'json', 
        'cache': true 
       }); 
      }, 
    });   

    $('#min_max_value').change(function(){ 
     oTable.fnDraw(); 
    }); 
}); 
+0

すごいが、このように思える

は、私はウルの問題のためにfnServerData部にこのページを参照$ _POST [「min_max_value」]として、この分の最大値をつかむことができるようになりますうまく動かないかもしれません。ここで状況を更新してください。あとで努力していただきありがとうございます。 – swordfish

+0

ちょっと、データがCIコントローラに返送されていないようです。テーブル – swordfish

+0

奇妙なCIコントローラがデータを受信して​​いないため、Firebugをインストールしてconsole.debug(data)を置くことができます。このdata.push({...})コードの直後 – Aman

関連する問題