0

Hello I'm in the middle of a Intranet development and i'm using DataTable in 4 different tables but just one works well, how can i change this situation?

PHP Page(Have some words in Portuguese):

https://pastebin.com/xutdL6bc

And this is the JavaScript file

$(document).ready(function() {
    $('#example').dataTable();
} );

If i change the class of the table the "beauty" will not work

1 Answer 1

2

UPDATE

I have looked up the API and I found the documentation that discusses having two tables. They achieve this based on the class of those tables. So in your case it would be table.beauty:

$(document).ready(function() {
    $('table.beauty').DataTable();
} );

Then get the table with the needed class:

<table id="" class="beauty" cellspacing="0" width="100%">

For more documentation look under their docs. It has all the information on there that you will need to get started with the code.


No, it would not, because in your current code changing the class will do absolutely nothing since you are calling the element by its id (#example). You are calling the jQuery element by ID value: #example. In practice you would have to change the JavaScript if you want the code to be applied by class.

// only the element with the id of example
$(document).ready(function() {
    $('#example').dataTable();
} );

If you want to get based on class change the # to a .. That would look like:

// any element with the class of example
$(document).ready(function() {
    $('.example').dataTable();
} );

NOTE: Your code is using mysql functions which are depricated, I know you were not asking about that; but if you are learning PHP I recommend you learn to use Mysqli or PDO would be far more beneficial.

Sign up to request clarification or add additional context in comments.

9 Comments

Note that depending on the configuration options passed to the DataTable, there may need to be 4 separate calls. $("#example").dataTable(); $("#example2").dataTable();...etc.
That is true, but he changes to class names than that shouldn't be a problem.
What I'm saying is that you can't necessarily do it in 1 call, because the configuration for each table may be (and is likely to be) different.
Como assim? Are you getting errors? Look under your console for any error messages. @RafaelBreno
I've tried to change to $(".example") and doing the same in 4 different calls(changing the id in the php file too)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.