Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Filtering smart-table on transformed data

{
  "prop_to_search1": "value1",
  "prop_to_search2": "value2",
  "prop_to_search3": "value3"
}
Comment

Filtering smart-table on transformed data

angular.module('myApp').filter('transactionFilters', function($rootScope, $filter){
  return function(array, expression){
    // console.log(`expression is: ${JSON.stringify(expression, null, 4)}`)
      return array.filter(function(val, index){
        // in this function's context, `expression` is an object with
        // the active filters entered in each field; `val` is the data
        // representation of each row of the table

        // if this function returns true, the row will match and smart-table
        // will show it, otherwise it will be hidden

        // define matches all at once, check them all, then return
        // a big logical AND on all of them

        let accountMatch = true;
        let payeeMatch = true;
        let categoryMatch = true;

        if (expression.account) {
          uuidToSearch = val.account  // this is the account UUID
          strToSearch = $rootScope.dbCtrl.getAccountName(uuidToSearch).toLowerCase();  // convert to an account name (we could memoize this to improve performance)
          if (strToSearch) {
            // if the account had a name (it always should, but catch in case)
            // then check if the row's account contains the text entered in the filter field
            accountMatch = strToSearch.includes(expression.account.toLowerCase());
          } else {
            accountMatch = false;
          }
        }

        if (expression.payee){
          if (val.payee) {
            uuidToSearch = val.payee
            strToSearch = $rootScope.dbCtrl.getPayeeName(uuidToSearch).toLowerCase();
          }

          if (strToSearch) {
            payeeMatch = strToSearch.includes(expression.payee.toLowerCase());
          } else {
            payeeMatch = false;
          }
        }

        if (expression.category) {
          if (val.category) {
            strToSearch = $rootScope.dbCtrl.getCategoryName(val.category, val.date).toLowerCase()
            categoryMatch = strToSearch.includes(expression.category.toLowerCase())
          } else {
            categoryMatch = false;
          }
        }

        return (
          accountMatch && 
          payeeMatch &&
          categoryMatch
        )
    })
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: Calculating state happens to late 
Javascript :: Changing Component File location in React native does not show in main App 
Javascript :: Why does the react-native-elements form show me a line below the Input 
Javascript :: How do I change this React Navigation v5 code to v6 
Javascript :: Error thrown after ending the audio track / array of tracks in React Native Track Player 
Javascript :: react js graph with more than one y axis 
Javascript :: Add and remove required attribute based on whether it is visible or hidden 
Javascript :: arrow function - one line and no parameters 
Javascript :: How to change a key value pair within a nested json structure C# 
Javascript :: in express remove page ,sort ,limit and fields from req.query 
Javascript :: Streaming search queries with Node.js and Socket.io (streaming to a given socket 
Javascript :: to fix a broken class oop javascript 
Javascript :: FlatList load top 
Javascript :: show hide div in javascript 
Javascript :: Exporting And Importing From A Module 
Javascript :: javascript get next month name 
Javascript :: Class Which Can Create An Instance Of The Same Type 
Javascript :: for in loop of javascript 
Javascript :: A Node Module For ReactJS 
Javascript :: Javascript Area When All Sides are Known 
Javascript :: board in javascript 
Javascript :: Use Dynamic Scales 
Javascript :: jquery properties 
Javascript :: create object in jquery dynamically 
Javascript :: winston transport file another directory 
Javascript :: Backbone Model Fetch 
Javascript :: How do I target and change the style of a different element when I click a button in react 
Javascript :: run javascript after rendering 
Javascript :: how to scroll element in javascript 
Javascript :: js 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =