When I disable "hide the table before it is fully loaded" the table shown as they should. <--NOTE: THIS IS KEY
In addition, I change Id of the table in order it does not create a conflict with other table. It is because when it used do_shortcode('[wpdatatables id=x]' ), it return always 'table_1' so It should be change to do not get a conflict with the others tables in the page.
I left the script for reference. I hope it will be helpful.
There's a data atribute in the table data-wpdatatable_id which shows the ID of the table. At the moment, the ID of the table is generated starting from "1", and it is oddly incremented, so there are multiple different IDs on a page. This means that if you have 3 tables on a page, they would be table_1, table_3 and table_5.
To follow the ID of the table, we would need to change the logic of the plugin, and its code.
All wpDataTables existing on the page are reflected in the global JavaScript object called ‘wpDataTables‘. If you check this variable in the JS developer console you will see the wpDataTables as properties of this object:
As you can see in the screenshot above, table_1 is the 1st table loaded on the page. Back when this ticket was created, each table received an odd object number, so if there were 3 tables on the page, they'd be:
table_1
table_3
table_5
If I'm not mistaken, that's not how it works anymore, so 3 tables on the page would be:
table_1
table_2
table_3
But I'd still advise inspecting them through the browser's Console in order to see the correct ID.
I am not aware of what exact code Alejandro used. All I know is what he wrote in this ticket.
I can see that you've opened another ticket with a similar request, and that my colleague is already covering it. I'll talk to him about your needs and we'll respond as soon as possible.
In our application we are trying to show a couple of table with an ajax request (adding an action hooks)
So we try this in our funtion.php
Function table(){
echo do_shortcode('[wpdatatables id=80]'
}add_action('wp_ajax_table', 'table')
The table shows but it seem that it does not has format. No like we use the standar shortcode '[wpdatatables id=80]' in any par of the website.
Any suggestion to get the table from an ajax request?
Alejandro
I figure it out.
When I disable "hide the table before it is fully loaded" the table shown as they should. <--NOTE: THIS IS KEY
In addition, I change Id of the table in order it does not create a conflict with other table. It is because when it used do_shortcode('[wpdatatables id=x]' ), it return always 'table_1' so It should be change to do not get a conflict with the others tables in the page.
I left the script for reference. I hope it will be helpful.
I use table_20 as a replace. You could use any.
function gettable1() {
$html = do_shortcode('[wpdatatable id=80]');
$html = str_replace('table_1','table_20',$html);
print_r( $html, false );
wp_die();
}
add_action('wp_ajax_gettable','gettable1');
and in you javascript code something like:
$.('#yourdiv').html(str_html)
$('#table_20).Datatable(); //draw your table
Hello Alejandro
Thanks for sharing the solution with us. I'm sure it will be helpful for our other users as well.
If you have any further questions or issues, please feel free to open a new ticket, and we'll gladly help.
Best regards.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Hi Aleksander.
Another question.
In the regular load page (no ajax) Im doing this:
I called more than once $html = do_shortcode('[wpdatatable id=80]'); its mean:
$html = do_shortcode('[wpdatatable id=80]'); //it return always table_1 as id
...
....
$html = do_shortcode('[wpdatatable id=92]'); //but it return any id table. table_3 or table_23 etc. Any id.
The thing is, How can I identify this id if I save in the $html the result of the do_shortcode?
Any easy way to get the current wpdatatable id used? any function in the library?
Hello Alejandro
There's a data atribute in the table data-wpdatatable_id which shows the ID of the table. At the moment, the ID of the table is generated starting from "1", and it is oddly incremented, so there are multiple different IDs on a page. This means that if you have 3 tables on a page, they would be table_1, table_3 and table_5.
To follow the ID of the table, we would need to change the logic of the plugin, and its code.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
I know this is a 3 year old ticket but I am having the same exact issue. Can you provide some more detailed code to address this issue?
Hello Jeff.
All wpDataTables existing on the page are reflected in the global JavaScript object called ‘wpDataTables‘. If you check this variable in the JS developer console you will see the wpDataTables as properties of this object:
As you can see in the screenshot above, table_1 is the 1st table loaded on the page. Back when this ticket was created, each table received an odd object number, so if there were 3 tables on the page, they'd be:
table_1
table_3
table_5
If I'm not mistaken, that's not how it works anymore, so 3 tables on the page would be:
table_1
table_2
table_3
But I'd still advise inspecting them through the browser's Console in order to see the correct ID.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Thanks for the reply, I understand that. What I don't understand is the code he used. Is it possible to give me a quick example?
Hi again Jeff.
I am not aware of what exact code Alejandro used. All I know is what he wrote in this ticket.
I can see that you've opened another ticket with a similar request, and that my colleague is already covering it. I'll talk to him about your needs and we'll respond as soon as possible.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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