Okay
  Public Ticket #2758214
Using variables in calling the plugin
Closed

Comments

  • Amir Zubovic started the conversation

    Dear All,
    I use the wpDataTables plugin and Powerfull Filters for wpDataTables.
    Before starting the plugin, I would like to select the values of the variables and run the plugin by filtering the data by the specified variables.
    I tried in WordPress with code
    <script>
      var godina= "2020";
      var mjesec= "06";
    </script>
    [wpdatatable id = 1 var1 = godinavar2 = mjesec]
    and I used Select * From ViewListaDrustavauOpcini Where godina=%VAR1% And mjesec=%VAR2% in the SQL call.
    The result is that I got a data set without filters by the specified variables.
    Please help me how I need to do the code to pass the values of the variables to the call plugin.
    Greetings,
    Amir
    

  • [deleted] replied

    Hi Amir

    Thank you for reaching out to us.

    You can add a filter through the shortcode only if you assign one of our placeholders to column settings/filters/predefined filtering value.

    If you add %VAR1% as a predefined filtering value to ColumnA, for example, it will load all the data (because the placeholder is not defined in the Placeholders tab above the table). Then, when you add the shortcode like:

    [wpdatatable id=1 var1=150] it will filter the table per columnA with the value of "150".

    Side note: By your name, I'd say you're from one of ex Yugoslavia countries, so if you'd like we can continue in Serbian (Croatian, Bosnian, Montenegrin). We're based in Belgrade.

  • Amir Zubovic replied

    Moje poštovanje Blaženka,

    Zahvaljujem na brzom odgovoru. Ja sam već koristio način kako ste naveli i to radi super. Želio bih da izbor varijabli koje koristim za filter prebacim izvan plugin-a i da ih pozovem u plugin-u koristeći njihov vrijednosti npr. [wpdatatables id=1 var1=godina var2=mjesec]. 
    Zamolio bih primjer na koji način da to najjednostavnije odradim (koristim Wordpress i Divi temu).
    Ovakav primjer koji sam uradio ne prenosi vrijednosti varijabli u plugin:
    <script>
       godina="2020"
       mjesec="06"  
    </script>
    [wpdatatables id=1 var1=godina var2=mjesec]

    U SQL upitu je Select * From nesto Where godina=%var1% and mjesec=%var2%

    Još jedna mala sugestija: Ubacivanjem interaktivnih mapa u paket imali bi ste najbolji plugin za prikaz podataka koji sam imao prilike vidjeti (bili bi tri svjetlosne godine ispred konkurencije).

    Lijep pozdrav iz Sarajeva,

    Amir

  • [deleted] replied

    Poštovanje

    Nažalost takav kod ne može biti izvršen jer su varijable napisane između script tagova, a var iz shortcode-a se izvršava na serveru, ne na frontu gdje je javascripta.

    Ako Vam treba dinamičko mijenjanje placeholdera to možete postići preko hook-a za dinamičke placeholdere:

    function updateVAR1andVAR2($tableID){  
    global $wdtVar1, $wdtVar2;      
    // check for specific table id
        if($tableID == 1)){
            //get value from form field
            $wdtVar1 = '2020';
            $wdtVar2 = '06';
        }
      }
    // or if he send that data over GET parameters
    // this is just example, he can pull data from database, some other resource
    // but he will need to make logic to get those data and to provide
    // it to placeholders variables
    //
    // if($tableID == 1)){
    // check is set GET parameter godina
    //    if(isset($_GET['godina'])){
            //get value from that parameter
    //        $wdtVar1 = $_GET['godina'];
    //    }
        //check is set GET parameter mesec
    //    if(isset($_GET['mesec'])){
            //get value from that parametar
    //        $wdtVar1 = $_GET['mesec'];
    //    }
    //  }
    // }
    add_action('wpdatatables_before_get_table_metadata', 'updateVAR1andVAR2');
    

    sve sa // je komentar i neće biti izvršeno, tu je primjer ako koristite GET parametre.

    Nadam se da Vam ovo može pomoći, slobodno nam se javite ako Vam je potrebna dodatna pomoć.