0

Desipite reading numerous answers related to this issue, I have not been able to understand how to implement Promises in my example. 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. I know I need to use Promises (instead of callbacks since Promises appear to be the future).

OverflowingTheGlass
  • 2,324
  • 1
  • 27
  • 75
  • "I know I need to use Promises (instead of callbacks since Promises appear to be the future)." — You don't have to use promises and you already have a callback you can use. – Quentin Feb 13 '20 at 17:24
  • How do I apply that though? I have read the answer you linked to many times, and I haven't been able to get it in my mind how I can apply it to my situation. What do you mean by "you already have a callback"? – OverflowingTheGlass Feb 13 '20 at 17:29
  • @Quentin I think you mean that the anonymous function where I am assigning `yadcf_data_2` is the callback function that could be called later. If that's the case, how would I call that later without `json` being defined outside of the `ajax` piece? – OverflowingTheGlass Feb 13 '20 at 17:38
  • This question is basically about your exact problem: https://stackoverflow.com/q/14220321/258482 – Arlen Beiler Feb 14 '20 at 00:03
  • Again, I've read that question numerous times and tinkered with my code to try to get different results. I'm probably too dense to understand some of this. Thanks for trying. – OverflowingTheGlass Feb 14 '20 at 14:33

0 Answers0