0

I have two dataTables on the same page, like this example: https://datatables.net/examples/basic_init/multiple_tables.html

Until no problem ..

It shares many parameters in common, for example for buttons or language

$('table').DataTable({
  language: {
    search: "",
    searchPlaceholder: "Search ...",
    sLengthMenu:"_MENU_",
    sInfo:"_TOTAL_ elmt",
    infoFiltered: "",
    sInfoEmpty: "0 elmt",
    "oPaginate": {
      "sPrevious": "<",
      "sNext": ">"
    }
  }
});

However, I wish to give them different pageLength sizes and different tries, How can I do ?

Knowing that the ID of the first table is table-one and the ID of the second is table-two

3
  • 1
    Why don't you just do $('#table-one').DataTable() and $('#table-two').DataTable() and give everyone it's own params? Commented Jan 4, 2019 at 11:14
  • @IslamElshobokshy Because there is more parameter in common than of different parameter, so I wanted to avoid the redundancy of the code Commented Jan 4, 2019 at 11:20
  • If there is even 1 different parameter then you need to duplicate all of the code, there's no going through that unfortunately. Commented Jan 4, 2019 at 11:20

1 Answer 1

2

Do this:

// create an object with your settings for the first table
var dataTableOptions = {
  language: {
    search: "",
    searchPlaceholder: "Search ...",
    sLengthMenu:"_MENU_",
    sInfo:"_TOTAL_ elmt",
    infoFiltered: "",
    sInfoEmpty: "0 elmt",
    "oPaginate": {
      "sPrevious": "<",
      "sNext": ">"
    }
  }
};

// initialize that table
$('#table1').DataTable(dataTableOptions);

// modify whatever settings you need to in the object you created
dataTableOptions.language.sLengthMenu = "some new value";

// use the modified object to initialize the second table
$('#table2').DataTable(dataTableOptions);
Sign up to request clarification or add additional context in comments.

3 Comments

This is only for translation, how do you set diferent length pages?
@Dani you should read the comments "// modify whatever settings you need to in the object you created" the given property was simply an example. You can change any property thats needed
Yeah i understand know, i was thinking in json traslations of datatable... Sorry and good answer

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.