2017-01-22 1 views
0

私はAjax経由でロードしているデータテーブルを持っています。サーバー側の 私はテーブルのデータを準備していて、別のデータ用に別のデータを準備しています テーブルロードの横に、別のデータを用意しています。 私は私のajaxコードを追加しました。成功イベントですが、それはテーブルの読み込みを置き換え、私は他のことを行うことができます テーブルの読み込みと他のものとの間で分離することはできません。ロードテーブルの横に何かをする

私も試してみましたfnDrawCallbackが、私は他の事 のデータを渡す方法がわからないここで成功イベントとAjaxコードです:

"ajax": { 
     "url": "/Entreaties/GetEntreaties", 
     "data": function (d) { 
      d.status = 0; 
      d.firstLoad = firstLoad;     
      d.jAdvanceSearch = JSON.stringify(new AdvanceSearch()); 
      d.freeText = $("#table_filter input").val(); 
     }, 
     "type": "POST", 
     "dataType": "json", 
     success: function (data) { 
      $.each(data.contactWaySum, function (key, value) { 
       alert(key + ": " + value.ContactWay); 
      });     
     }, 
     error: function (xhr, textStatus, errorThrown) { 
      console.log(xhr.responseText); 
     } 
    }, 
私は右のあなたを理解していれば

あなたはDataTableのAJAXに建てられていますが、一度にいくつかのことをやってみたかったので止めに使用していた、あなたの助け

答えて

0

ありがとうございました。その場合は、DataTable ajaxを使用して戻り、dataFilter関数を使用してそれらを分離して適用します。ここで

は一例です:

// If your server side sends back somehting that looks like this for the data table (this is what it is expecting) 

      {draw:1, recordTotal:20, recordsFilter:20, data:dataSet } 

      // adjust your json to look like 


      // If the json object return looks like what the 
      { dataTableData:{draw:1, recordTotal:20, recordsFilter:20, data:dataSet }, otherStuffData: otherData} 

      $("#sometable").DataTable({ 
       // other data table stuff left out to save space 
       "serverSide": true, 
       "ajax": { 
        "url": "you url" , 
        "data": function (ssp) { 
         // Do the stuff you need to to get your paramerters ready 
         // server side parameters (ssp) are documented at http://datatables.net/manual/server-side 
         // in addition to the ssp parameters, the name of the column is pulled from the table header column 


         return ssp; 

        }, 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        error: function (a, b, c, d) { debugger; }, 
        dataFilter: function (data) { 

         // call function or what ever you need to do with the other data here 

         doOtherStuff(data.otherStuffData); 

         // the web method returns the data in a wrapper 
         // so it has to be pulled out and put in the 
         // form that DataTables is expecting. 

         //return just the datatable data here 
         return JSON.stringify(data.dataTableData); 
        } 
       } 
      }); 
関連する問題