How to filter a very large bootstrap table using pure Javascript

前端 未结 7 2159
清歌不尽
清歌不尽 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:56

    see this link it might help, the only problem is its not in pure javascript it also uses angularjs.

        app.service("NameService", function($http, $filter){
    
      function filterData(data, filter){
        return $filter('filter')(data, filter)
      }
    
      function orderData(data, params){
        return params.sorting() ? $filter('orderBy')(data, params.orderBy()) : filteredData;
      }
    
      function sliceData(data, params){
        return data.slice((params.page() - 1) * params.count(), params.page() * params.count())
      }
    
      function transformData(data,filter,params){
        return sliceData( orderData( filterData(data,filter), params ), params);
      }
    
      var service = {
        cachedData:[],
        getData:function($defer, params, filter){
          if(service.cachedData.length>0){
            console.log("using cached data")
            var filteredData = filterData(service.cachedData,filter);
            var transformedData = sliceData(orderData(filteredData,params),params);
            params.total(filteredData.length)
            $defer.resolve(transformedData);
          }
          else{
            console.log("fetching data")
            $http.get("data.json").success(function(resp)
            {
              angular.copy(resp,service.cachedData)
              params.total(resp.length)
              var filteredData = $filter('filter')(resp, filter);
              var transformedData = transformData(resp,filter,params)
    
              $defer.resolve(transformedData);
            });  
          }
    
        }
      };
      return service;  
    });
    

提交回复
热议问题