The number range filter in ng-table is malfunctioning

  • what I am trying to accomplish

My goal is to create a column that can accommodate two numbers in order to filter numeric data within a specific range for that column. While sorting, pagination, and filtering by 'contain text' are working correctly, I'm unsure of how to implement a 'range' filter for just one column.

  • Visual representation of my objective

    column_header1    columns_header2         column_header3
    
    contain_filter1   contain_filter2         filter3_min_number
                                              filter3_max_number
    
      data                 data                   numeric data
        .                    .                          .
        .                    .                          .
        .                    .                          .
    
  • Current progress

I came across an example on the ng-table module website and attempted to integrate their code into mine, particularly focusing on implementing the range function within my 'getData'. The example I referenced: http://codepen.io/christianacca/pen/yNWeOP. I was inspired by the custom filter algorithm applied to 'age' data.

  • Snippet from my app.js

    $http.get("http://hostname:port/variant/whole/1-10000", {cache: true})
        .then(function (response) {
    
            $scope.variants = response.data;
    
            $scope.data = $scope.variants;
            var self = this;
            self.variantFilterDef = {
                start: {
                    id: 'number',
                    placeholder: 'Start'
                },
                end: {
                    id: 'number',
                    placeholder: 'End'
                }
            };
            
            // Implementing range filter with NgTableParams
            
    
            /* Further operational code without 'Range' functionality */
    
    
        });
    
    
    
    
    
    
  • Snippet from my variant.html

    <table ng-table="variantsTable" show-filter="true" class="table table-bordered table-striped table-condensed">
          <tr ng-repeat="variant in $data">
    
    
       <td data-title="'chrom'" sortable="'chrom'" filter="{ 'chrom': 'text' }" >
    {{variant.chrom}}
       </td>
    
      <td data-title="'id'" sortable="'id'" filter="{ 'id': 'text' }" >
    {{variant.id}}
      </td>
    
    
      <td data-title="'pos'" sortable = "'pos'" filter = "{ 'pos': 'text' }">
    {{variant.pos}}
      </td>
    

I would greatly appreciate any suggestions or input on this matter. Thank you!

Answer №1

The filter attribute in the ID cell of the table is incorrect.

<td data-title="'id'" sortable="'id'" filter="{ 'id': 'text' }">
    {{variant.id}}
</td>

Update it to:

<td data-title="'id'" sortable="'id'" filter="variantFilterDef">
    {{variant.id}}
</td>

UPDATE

After some experimentation, I managed to get it to work. I began with your code example and made several modifications. I utilized ControllerAs syntax. The key fixes were:

  1. <td data-title="'chrom'" sortable="'chrom'" filter="{ 'chrom': 'text' }">

    changed to

    <td data-title="'chrom'" sortable="'chrom'" filter="{ 'name': 'text' }">

  2. <td data-title="'pos'" sortable = "'pos'" filter = "{ 'pos': 'text' }">

    changed to

    <td data-title="'pos'" sortable="'pos'" filter="variantCtrl.variantFilterDef">

  3. if (params.filter()) {
            self.data = $filter('filter')(self.data, {name: params.filter().name});
            self.data = variantRangeFilter(self.data, params.filter());
        } else {
            self.data = self.data;
        }

The main issue was ensuring that the filters for each column in #3 were separated using {name: params.filter().name}) and then calling the custom Pos filter separately.

Codepen Link: http://codepen.io/anon/pen/QKBYOq?editors=1011

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Refreshing the page causes Firebase authentication to vanish

My React app integrates Firebase authentication. However, I am facing an issue where the firebase:authUser is stored in localStorage upon successful login, but gets cleared on every page refresh resulting in a lost session. Surprisingly, browsing through o ...

An error was encountered when trying to read property '0' of an undefined object in a for loop

Currently, I am working on a project to create a mastermind game. Everything is progressing smoothly, except for one issue that keeps popping up - I keep encountering the error: "uncaught typeerror cannot read property '0' of undefined." fun ...

How to dynamically add variables to object paths using JavaScript and Angular

I've been struggling to grasp this concept, despite hours of searching. My goal is to dynamically generate form fields based on a user-selected 'type' from a dropdown menu. This will be linked to the variable "currentType" in Angular, which ...

Is it more efficient to declare a variable or directly return the variable from the Element's getText() promise in Protractor?

I am facing a scenario where I need to retrieve the text of a web element using a promise and then extract a specific part of the string for further processing. Which example, the one at the top or the bottom, should I use? var id = element(by.binding( ...

Is the functionality of this.value compatible with Firefox but not with Internet Explorer?

I am facing an issue with the onChange event on a select element. When I use alert(this.value), it works fine on Firefox, but not on Internet Explorer. What could be causing this discrepancy? Below is the code snippet in question: <select onchange="n ...

retrieve the previous value from the scope

Attempting to create a copy of an event before any changes are made in order to implement a cancel button, I stored it in the oldValue variable. However, both the event and oldValue variables appear to be empty because they are executed before the event fa ...

The Markdown-to-jsx tool is having trouble processing the provided source code

Utilizing a Material UI blog post template found at https://github.com/mui-org/material-ui/tree/master/docs/src/pages/getting-started/templates/blog, I have created my React app using npx create-react-app. Upon console logging the source, it displays as a ...

Creating dynamic ColumnDefs for UI Grid is essential for responsive and flexible data

I am currently facing a challenge with my angular UI Grid setup for populating data in reports. With almost 20 reports to handle, I am looking to streamline the process by using one UI Grid for all of them. To achieve this, I am attempting to dynamically c ...

The datetimepicker is not functioning properly

I'm experiencing an issue with the datetimepicker where it doesn't display a calendar when I click the icon. Interestingly, the Chrome browser isn't showing any errors in the development console. <script src="Scripts/jquery-2.1.1.min.js ...

What is the reason for instanceof Map returning false?

Utilizing the Draft.js plugin called Mention. When accessing editorState.content.entityMap.mention, I am able to retrieve the value by: mention.get('address') However, when I attempt to verify if it is a Map using: console.log('mention&a ...

Unable to locate the node module within the Rails stimulus controller

I'm facing an issue with integrating my own npm package into a Rails application that I have developed. It's unclear whether the problem lies in the creation of the node package or within the rails app itself. The package in question is fairly ...

Utilizing classes as types in TypeScript

Why is it possible to use a class as a type in TypeScript, like word: Word in the provided code snippet? class Dict { private words: Words = {}; // I am curious about this specific line add(word: Word) { if (!this.words[word.term]) { this.wor ...

Obtaining the data stored in objects within a parse database

I'm currently facing an issue where I am trying to retrieve the name of the creator from the session object, which is a pointer. For testing purposes, I have been attempting to access this information but it keeps showing up as undefined. Any suggesti ...

Create a parent dropdown class that contains two separate bootstrap dropdowns nested within it

I am encountering an issue with my dropdown menus. I have 2 dropdown menu items under the same parent dropdown class. However, when I click on dropdown action 1, it displays the body of dropdown menu 2 items instead. <!DOCTYPE html> <html> < ...

What is the best way to send a string parameter from an Angular UI to a Node.js backend?

My goal is to transfer a string value from an Angular UI to a Node.js backend API, which will then search in MongoDB using the provided string value as shown below. I am attempting to receive input in enteredValue and pass it on to the http.get call as pa ...

What is the best way to transfer JSON data to a different controller in AngularJS?

Hello, I'm still learning AngularJS and facing an issue with the following code snippet. app.config(function($routeProvider) { $routeProvider .when('/', { templateUrl: "partials/home.html", controller: "mainControlle ...

Is there any importance to port 9229 and is it possible to modify it?

In my initial training, it was always recommended to run a local Node server on port 3000. However, after learning about the Chrome Node debugger in a tutorial that uses port 9229, I decided to switch to this port. For more information on port 3000, you ...

Tips for making an appended element match the height of an image

After embedding the div .soonOverlay into specific .smallCatalogBlock's, I am facing difficulty in adjusting the height of soonOverlay to match only the height of the img within smallCatalogBlock. Currently, its height extends throughout the entire co ...

Error encountered in onclick handler due to unterminated string literal in PHP and jQuery

Trying to utilize PHP to send variables into the onclick of an element is resulting in an "Unterminated string literal" error due to long strings. Below is a snippet of my PHP code: $query = $conn->prepare("SELECT Name, Image, Description, Link, Price, ...

Steps to Create an HTML Text Box that cannot be clicked

Does anyone know of a way to prevent a text box from being clicked without disabling it or blocking mouse hover events? I can't disable the text box because that would interfere with my jQuery tool tips, and blocking mouse hover events is not an opti ...