Hey there, Awesome Customers!

Just a heads up: We'll be taking a breather to celebrate International Workers' Day (May 1st and 2nd - Wednesday and Thursday) and Orthodox Easter from Good Friday (May 3rd) through Easter Monday (May 6th). So, from May 1st to May 6th, our team will be off enjoying some well-deserved downtime.

During this time, our customer support will be running on a smaller crew, but don't worry! We'll still be around to help with any urgent matters, though it might take us a bit longer than usual to get back to you.

We'll be back in action at full throttle on May 7th (Tuesday), ready to tackle your questions and requests with gusto!

In the meantime, you can explore our documentation for Amelia and wpDataTables. You'll find loads of helpful resources, including articles and handy video tutorials on YouTube (Amelia's YouTube Channel and wpDataTables' YouTube Channel). These gems might just have the answers you're looking for while we're kicking back.

Thanks a bunch for your understanding and support!

Catch you on the flip side!

Warm regards,

TMS

Okay
  Public Ticket #2211229
How to add custom JS to URL Buttons
Closed

Comments

  •  10
    michiiee started the conversation

    Hi there,

    i have a short question. Is there a way how to add custom JS when the user clicks on a URL Button of a table? I had no success how to correctly identify the id of that row.

    It would be great if you could provide me a short example/idea how it could work. 

    My aim is to trigger a simple alert when the user clicks the url button.

    Many regards,

    Michael



  •  2,499
    Aleksandar replied

    Hello Michael.

    Rows are stored as evens and odds - there are no row numbers in the code.

    You could probably use some of our filters and hooks to do this, but it'd have to be custom developed, and unfortunately custom work is not included in the provided support for the plugin.

    I guess a hook like this may help:

    wpdatatables_after_frontent_edit_row

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  10
    michiiee replied

    Hi there,

    well, i figured out how it can work, so maybe you are wrong. There is quite a simple solution for that imo.

    If you just create a simple concat in the sql query like this

    CONCAT('<button type="button", class="anmeldung_ablehnen", id=', turnier_id, '>Click Me!</button>') AS test

    you are able to address the button with jquery by the class selector

    jQuery(document).on( 'click', '.anmeldung_ablehnen', function (e) {

    and you can get the id by

    var turnier_id = this.id;

    I still havent tried further yet, but that means that i can now write custom JS code with e.g. an ajax request to do whatever i want with the row and its id.

    Many regards,

    Michael



  •  2,499
    Aleksandar replied

    Hello Michael.

    You are correct, and that may just work.

    But, you'd be assigning an ID yourself here "id=', turnier_id, ' ", correct?

    What I said is that rows are recorded like this:

    7262279371.png

    So, they have no ID by default, but with your custom solution, it just may be possible.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Neil Williams replied

    Hi Michiiee,

    I am really interested how you solved this, is it possible to give more of an explanation, what type of code did you use? where you issued the sql statement?

    I am trying to add data to a cell in a row from another input, ie if cell one is "Apple" cell 2 should be filled with an integer of 1 but hidden using javascript, I cant seem to use an integer as a foreign key ???

    Sorry to intrude on your post but seemed very interesting how you accomplished this. many thanks Neil

  •  10
    michiiee replied

    Hi Neil,

    well all tables i use are generated by the sql query option. So my sql query looks something like this:

    SELECT anmeldung_id, turnier_id, ...,
    CONCAT('<button type="button", class="anmeldung_annehmen", id=', turnier_id, '_', anmeldung_id ,'_', status_id , '>Anmeldung annehmen</button>') AS anmeldung_annehmen,
    CONCAT('<button type="button", class="anmeldung_ablehnen", id=', turnier_id, '_', anmeldung_id ,'_', status_id , '>Anmeldung ablehnen</button>') AS anmeldung_ablehnen
    FROM ... WHERE ....


    I have set the columns for the concat statetments just to the data type string. A simple button is displayed in the frontend then.


    In the custom JS section of my theme i added something like this:

    jQuery(document).on( 'click', '.anmeldung_annehmen', function (e) {
    var id = this.id;
    var split = id.split("_");
    var turnier_id = split[0]; 
    var anmeldung_id = split[1];
    var status = split[2];


    With this code i can trigger some JS when the button with class anmeldung_annehmen is clicked.

    With the split function i can read all the ids (or whatever you have used for the id of the button) into a variable.