Skip to content
This repository has been archived by the owner on May 30, 2021. It is now read-only.

Fix shared options between instances of DataTables #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Co-qn
Copy link

@Co-qn Co-qn commented Mar 30, 2018

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",
            "nunc.ullamcorper@metusvitae.com",
            "070 8206 9605"
        ],
        [
            "Genevieve U. Watts",
            "Eget Incorporated",
            "9557",
            "07/18/2017",
            "Nullam.vitae@egestas.edu",
            "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.

@johanneswilm
Copy link

@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).

@Mobius1
Copy link
Owner

Mobius1 commented Mar 30, 2018

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants