Sha256: 5e7509a2ae63b901e02a391a82daae3b524cbbc7b44a0c1a1e8452c68dcbcc7f

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

<script type="application/javascript">
    function _hideTableElement(elm) {
        elm.style.display = "none";
    }

    function _showTableElement(elm) {
        elm.style.display = "";
    }

    function _filterTable(value) {
        var tableRows = document.querySelectorAll('[data-table-filterable]');

        for (var i = 0; i < tableRows.length; i++) {
            var row = tableRows[i];

            if (value == "") {
                _showTableElement(row)
            } else {
                if (row.dataset.tableFilterable.includes(value)) {
                    _showTableElement(row)
                } else {
                    _hideTableElement(row)
                }
            }
        }
    }

    var _tableFilterInput = document.querySelector('[data-table-filter]');

    var _hasFilteredTableInput = false;
    _tableFilterInput.addEventListener('input', function handleInput(input) {
        _hasFilteredTableInput = true;
        _filterTable(input.target.value)
    })

    _tableFilterInput.addEventListener('input', function handleInput(input) {
        _hasFilteredTableInput = true;
        _filterTable(input.target.value)
    })

    // Handling cases where the browser autofills on a back button navigation due to the bfc
    window.addEventListener('pageshow', function() {
      if (!_hasFilteredTableInput && _tableFilterInput) {
          _filterTable(_tableFilterInput.value)
      }
    });
</script>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rake-ui-0.1.0 app/views/partials/rake_ui/_table_filterable.html
rake-ui-0.0.1 app/views/partials/rake_ui/_table_filterable.html