How to filter a very large bootstrap table using pure Javascript

前端 未结 7 2158
清歌不尽
清歌不尽 2021-02-05 12:05

I\'ve built a large table in bootstrap, about 5,000 rows x 10 columns, and I need to filter the table for specific attributes, fast, using only JavaScript. The table has both an

7条回答
  •  我在风中等你
    2021-02-05 12:46

    More than searching, rendering eats up a lot of time and resources. Limit the number of rows to display and your code can work like a charm. Also instead of hiding and unhiding, if you print only limited rows, that would be better. You can check out how it's done in my opensource library https://github.com/thehitechpanky/js-bootstrap-tables

        function _addTableDataRows(paramObjectTDR) {
        let { filterNode, limitNode, bodyNode, countNode, paramObject } = paramObjectTDR;
        let { dataRows, functionArray } = paramObject;
        _clearNode(bodyNode);
        if (typeof dataRows === `string`) {
            bodyNode.insertAdjacentHTML(`beforeend`, dataRows);
        } else {
            let filterTerm;
            if (filterNode) {
                filterTerm = filterNode.value.toLowerCase();
            }
            let serialNumber = 0;
            let limitNumber = 0;
            let rowNode;
            dataRows.forEach(currentRow => {
                if (!filterNode || _filterData(filterTerm, currentRow)) {
                    serialNumber++;
                    if (!limitNode || limitNode.value === `all` || limitNode.value >= serialNumber) {
                        limitNumber++;
                        rowNode = _getNode(`tr`);
                        bodyNode.appendChild(rowNode);
                        _addData(rowNode, serialNumber, currentRow, `td`);
                    }
                }
            });
            _clearNode(countNode);
            countNode.insertAdjacentText(`beforeend`, `Showing 1 to ${limitNumber} of ${serialNumber} entries`);
        }
        if (functionArray) {
            functionArray.forEach(currentObject => {
                let { className, eventName, functionName } = currentObject;
                _attachFunctionToClassNodes(className, eventName, functionName);
            });
        }
    }
    

提交回复
热议问题