Vanilla-DataTables
Vanilla-DataTables copied to clipboard
Fix shared options between instances of DataTables
Summary
When using multiple data tables in a HTML, it seems that options for each instances are shared.
I discover it is because of the defaultConfig
object is broken changed when creating DataTable instances.
Example
var myData = {
"headings": [
"Name",
"Company",
"Ext.",
"Start Date",
"Email",
"Phone No."
],
"data": [
[
"Hedwig F. Nguyen",
"Arcu Vel Foundation",
"9875",
"03/27/2017",
"[email protected]",
"070 8206 9605"
],
[
"Genevieve U. Watts",
"Eget Incorporated",
"9557",
"07/18/2017",
"[email protected]",
"0800 106980"
],
]
};
var table1 = new DataTable("#dt1", { data: myData, perPage: 25 });
var table2 = new DataTable("#dt2", { });
Expected
-
table1
has set default perPage = 25. -
table2
has set default perPage = 10(default). -
table1
has 2 records. -
table2
has no records.
Actual(before fixed by this PR)
-
table1
has set default perPage = 25. -
table2
has set default perPage = 25. -
table1
has 2 records. -
table2
has 2 records.
@Co-qn Have you checked whether this is the only thing that is apparently leaking into the global namespace? I wonder if it would be an idea to refactor the entire thing as ES2015+ modules. That should stop leakage (as well as make the sources more readable by spreading them out into several files).
@johanneswilm - The ES2015+ module route was something I was considering. Maybe it's time to put it in to action as the library seems to be fairly popular. I'll look into refactoring after the weekend.