Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more than 1 filter doesn't work #15

Closed
mrjones-plip opened this issue Jun 22, 2016 · 6 comments
Closed

more than 1 filter doesn't work #15

mrjones-plip opened this issue Jun 22, 2016 · 6 comments
Labels

Comments

@mrjones-plip
Copy link
Contributor

if you try and add two filters to a maptable, only the first filter works. removing N filters so there's only 1 left, makes the sole filter work again.

@mrjones-plip mrjones-plip changed the title 1 + N filters don't work more than 1 filter doesn't work Jun 22, 2016
@melalj
Copy link
Member

melalj commented Jun 22, 2016

is it for all browsers?
Did you get any error message on the console?

@mrjones-plip
Copy link
Contributor Author

Tested in FF latest, Chrome latest and IE11. no errors on console :(

@melalj
Copy link
Member

melalj commented Jun 22, 2016

No time to pull the code.
Here's the changes that you need to make for https://github.com/Packet-Clearing-House/maptable/blob/master/src/components/Filters.js#L307

filterData() {
    const that = this;
    this.maptable.data = this.maptable.rawData.filter(d => {
      const rowNodes = document.querySelectorAll('.mt-filter-row');
      let matched = true;
      for (let i = 0; i < rowNodes.length && matched; i++) {
        const rowNode = rowNodes[i];
        const filterName = rowNode.getAttribute('data-mt-filter-name');
        const columnDetails = that.maptable.columnDetails[filterName];
        const fmt = columnDetails.dataParse; // shortcut

        if (columnDetails.filterMethod === 'dropdown') {
          const filterValue = rowNode.querySelector('.mt-filter-value').value;
          if (filterValue === '') continue;
          if (d[filterName] !== filterValue) matched = false;
        } else if (columnDetails.filterMethod === 'field') {
          const filterValue = rowNode.querySelector('.mt-filter-value').value;
          if (filterValue === '') continue;
          if (d[filterName].toLowerCase().indexOf(filterValue.toLowerCase()) === -1) {
            matched = false;
          }
        } else if (columnDetails.filterMethod === 'compare') {
          const filterRange = rowNode.querySelector('.mt-filter-range').value;
          if (filterRange === 'BETWEEN') {
            const filterValueMin = rowNode.querySelector('.mt-filter-value-min').value;
            const filterValueMax = rowNode.querySelector('.mt-filter-value-max').value;
            if (filterValueMin === '' || filterValueMax === '') continue;
            if (fmt &&
              (fmt(d[filterName]) < fmt(filterValueMin) ||
                fmt(d[filterName]) > fmt(filterValueMax))
            ) {
              matched = false;
            } else if (
              parseInt(d[filterName], 10) < parseInt(filterValueMin, 10) ||
              parseInt(d[filterName], 10) > parseInt(filterValueMax, 10)
            ) {
              matched = false;
            }
          } else {
            const filterValue = rowNode.querySelector('.mt-filter-value-min').value;
            if (filterValue === '') continue;
            if (fmt && !utils.rangeToBool(fmt(d[filterName]), filterRange, fmt(filterValue))) {
              matched = false;
            } else if (!fmt && !utils.rangeToBool(d[filterName], filterRange, filterValue)) {
              matched = false;
            }
          }
        }
      }
      return matched;
    });
  }

Let me know if that works 😉

EDIT: fixed

@mrjones-plip
Copy link
Contributor Author

same result: only one filter works and no errors in console.

@mrjones-plip
Copy link
Contributor Author

still the same, but this time i get an error in the console on the exact line I added (the if() one above):

ReferenceError: filterName is not defined

this didn't help:

if (filterName !== null && d[filterName] !== null && d[filterName].toLowerCase().indexOf(filterValue.toLowerCase()) !== -1) {
  matched = false;
}

mrjones-plip pushed a commit that referenced this issue Jun 22, 2016
@melalj
Copy link
Member

melalj commented Jun 22, 2016

I edited the previous comment

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

No branches or pull requests

2 participants