2013-03-11 47 views
0

請幫助基本上我想過濾我的數據表使用窗體。codeigniter datatables從表單獲取數據

每個輸入的值都會影響查詢和提交的表單。

這是我的JQUERY。

$("#submit").click(function (e) {    

    $('#table').dataTable 
    ({ 

     "sAjaxSource": "index.php/report/get_report",  
     "sServerMethod": "POST",   
     'fnServerData': function (url, data, callback) { 
     // Add new data 
      dataString = $("#myform").serialize(); 
      $.ajax({ 
       'url': "index.php/report/get_report", 
       'data': dataString, 
       'type': 'POST', 
       'success': callback, 
       'dataType': 'json', 
       'cache': true 
      }); 
     },       
     'bServerSide' : true, 
     "aaSorting": [[ 3, "desc" ]], 
     "bPaginate": true,      
     "bSortClasses": false, 
     "bAutoWidth": true, 
     "bInfo": true,   
     "iDisplayLength" : 3,   
     "bScrollCollapse": true,           
     "oLanguage": { 
      "sSearch": "Search:" 
     }, 
     "bDestroy": true   
    });  
});   

,這是我的HTML表單

<form name="myform">           
    <label>Employee:</label> 
    <input type="text" name="employeeid" id="employeeid" title="Type Employee" /> 
    <label>Training Type: </label> 
     <select name="trainingtype" id="trainingtype" > 
     <option value="" selected="selected">All</option> 
     <option value="1">Externally Facilitated Training</option> 
     <option value="3">Internally Facilitated Training</option> 
     <option value="2">Webcast/E-Learning</option> 
     </select>          
    <label>Datestart</label> 
    <input type="text" class="field size3" name="datestart" id="datepicker_s" />      
    <label>Dateend </label> 
    <input type="text" class="field size3" name="dateend" id="datepicker_e" />    
    <input type="hidden" id="txtsearchid" name="txtsearchid"> 
    <input type="button" class="button" value="Submit" id="submit" />    

當我提交表單我什麼也沒得到。

我正在做正確的方法?

請幫忙。

GOT IT

"fnServerData": function (sSource, aoData, fnCallback) { 
       //REQUIRED: Add a Post variable with the object value     
       aoData.push( 
        { "name": "txtsearchid", "value": $("#txtsearchid").val() }, 
        { "name": "datestart", "value": $("#datepicker_s").val() }, 
        { "name": "dateend", "value": $("#datepicker_e").val() }, 
        { "name": "trainingtype", "value": $("#trainingtype").val() } 

       ); 

       $.ajax({ 
         dataType: 'json', 
         type: "POST", 
         url: sSource, 
         data: aoData , 
         success: fnCallback 
       }); 
     }, 

這肯定是我的問題的解決方案。我沒有使用的序列化,而不是推

+0

http://www.grocerycrud.com/你可能想看看雜貨店CRUD,建於數據表/ flexigrid圖書館codeigniter,節省您的代碼從更長的行代碼,如果你想使用數據表的時間 – tomexsans 2013-03-11 07:49:48

+0

謝謝我已經找到了解決方案 – 2013-03-11 08:30:34

回答

0

使用Firebug從Mozilla的插件添加到檢查錯誤

+0

對不起,我不熟悉使用螢火蟲,但我認爲我有我的數據表jQuery的。我新來數據表。我只有使用基本用法的數據表的工作知識。 – 2013-03-11 06:22:24

+0

火狐是一款附帶的Mozilla Firefox跟蹤jQuery的錯誤..只是試圖研究它,它會幫助你很多... – jalborres 2013-03-12 00:53:29

+0

https://addons.mozilla.org/en-US/firefox/addon/firebug /只需下載這個螢火蟲,並學習如何使用它.. – jalborres 2013-04-26 01:59:40