简体   繁体   中英

Use variable from DataTables ajax response to populate yadcf filter

I have a DataTables table defined like this:

$(function () {
  var yadcf_data_3;
  var oTable = $('#example').DataTable({
    "serverSide": true,
    "ajax": {"url": "/platform/elements/?format=datatables",
             "dataSrc": function(json){
               yadcf_data_3 = json.options.yadcf_data_3
               //this line returns the appropriate list of values
               console.log(yadcf_data_3)
               return json.data;
              }
            }
          });

   //this line returns undefined
   console.log(yadcf_data_3)

   //other stuff      

  yadcf.exRefreshColumnFilterWithDataProp(oTable, 3, yadcf_data_3);
});

How do I use yadcf_data_3 to populate a filter for the table? yadcf_data_3 returns undefined outside of the oTable variable.

var table = $("#employeetable").DataTable({
                "ajax": {
                    "url": "/url",
                    "type": "POST",
                    "datatype": "json"
                    , dataSrc: function (data) {
                        CalculateSum= data.CalculateSum;
                        return data.data;
                    }
                }


....
 drawCallback: function (settings) {
                    var api = this.api();
                    $('#CalculateSum').html(CalculateSum);
                },
                "serverSide": "true",
                "order": [0, "desc"],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM