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

The type 'SVGPathSeg' cannot be assigned to type 'EnterElement' because the property 'ownerDocument' is not present in type 'SVGPathSeg'

I'm attempting to replicate this example using the d3-ng2-service service on Angular 5. Component: OnInit code: let d3 = this.d3; let d3ParentElement: Selection<HTMLElement, any, null, undefined>; let d3Svg: Selection<SVGSVGElement, any, n ...

Sharing Data Across Multiple Windows in Angular 2 Using a Singleton List

My multiplayer game involves adding new players to a single game room lobby, which is essentially a list of current players. How can I update this list for all connected players when new ones join? I implemented a service and included it in the providers ...

The failure to build was due to the absence of the export of ParsedQs from express-serve-static-core

Encountered the error message [@types/express]-Type 'P' is not assignable to type 'ParamsArray'. Resolved it by installing specific packages "@types/express": "^4.17.8", "@types/express-serve-static-core": ...

The loading of script files is not working properly in an AngularJS web API application

After developing an application in angularjs that utilizes angular routing for calling web api services, everything functions properly when run from visual studio. However, upon deploying the application on an IIS web server, the script files fail to load ...

Jasmine tests for AngularJS directive failed to invoke the link function

I can't figure out why the link function of my directive isn't being called in a Jasmine test. I've created a simple example to illustrate. Here is the code for my directive (TestDirective.js): 'use strict'; angular.module(&ap ...

Steps to show a Google Maps marker with the help of ajax

I'm trying to show a "marker" on the map using ajax, but I haven't been able to find a solution despite searching various sources online. ================= Here's the code I currently have: var map; function initialize(){ var center = ...

Guide to displaying database results in an HTML dropdown menu by utilizing AJAX technology

Greetings! As a newcomer to the realms of PHP and AJAX, I am currently on a quest to showcase the outcomes of a query within an HTML dropdown using AJAX. Let's delve into my PHP code: $pro1 = mysqli_query("select email from groups"); I made an attemp ...

AngularJS - Always keep an eye on a group of items

Looking to create a custom watcher for a collection within my application, I initially believed that Angular would have all the necessary tools at my disposal. I had access to $watch, both shallow and deep, as well as $watchCollection. A $digest cycle was ...

Updating an array in JavaScript with a dynamically generated key name while working in the ReactJS framework

I have multiple dropdown menus, and when I select an option from any of them, I want to store the selected value in the component state. The onChange function that I call looks like this: function handleSelect(event) { console.log(event.target.value); ...

What is the method for altering the date format of a published article?

I am looking to modify the date format of a published post in WordPress. Currently, the date format is <?php the_time('m.d.y'); ?></div>, which appears as "1.20.2018". My goal is to change it to "January 20, 2018". Can anyone guide ...

Using Javascript to display an element when scrolling within a specific container and each item of an array reaches the top

I'm just starting out with JavaScript and I'm attempting to create a scrollable div that includes items from an array. As the user scrolls and each item reaches the top, I want a hidden element to be displayed. Here's what I have so far: ...

How long do variables persist in a Factory in Angular JS?

Can anyone clarify the lifespan of variables stored in factory/services in Angular JS? Do the values persist after refreshing the page, or do they get reset? And what happens if we refresh the entire application? I am currently storing values in a factor ...

Tips on dividing the information in AngularJS

Sample JS code: $scope.data={"0.19", "C:0.13", "C:0.196|D:0.23"} .filter('formatData', function () { return function (input) { if (input.indexOf(":") != -1) { var output = input .split ...

Mapping a bar chart on a global scale

Are there any methods available to create bar charts on a world map? The world map could be depicted in a 3D view resembling a Globe or in a 2D format. It should also have the capability to zoom in at street level. Does anyone have suggestions or examples ...

My tests are not passing because I included a compare method in the Array prototype. What steps can I take to fix this issue in either the

Embarking on the challenging Mars Rover Kata has presented a unique problem for me. My jasmine tests are failing because of my array compare method within the prototype. This method is crucial for detecting obstacles at specific grid points. For instance, ...

Is it possible for a div with fixed position to still have scrolling functionality

My fixed positioned div (#stoerer) appears to be moving while scrolling, although it is just an optical illusion. Check out this visual explanation: view gif for clarification Below is the code snippet in question: <div id="stoerer"> <button ...

Exploring the world of jQuery animation and background colors with Animate()

I'm currently attempting to implement a basic pulse effect by utilizing JQuery to modify the background color. However, I am facing issues with animating the backgroundColor property. function show_user(dnid) { /* dnid represents the HTML ID of a ...

Utilizing zlib Compression with Node.js in a TCP Connection

I am currently embarking on my node.js journey, delving into the world of TCP servers. My goal is to ensure that all messages sent to clients are in a compressed format, utilizing zlib for this task. Here is an example of server-side code: zlib.deflate(r ...

ways of exporting and using arrays in Node.js

Constantly receiving the "undefined" error in main.js: var dbAccess = require('../dao/dbAccess'); dbaInstance = new dbAccess(); var wordPool = dbaInstance.getWordPool(); console.log (wordPool); The contents of "dbAccess.js" are as follows: var ...

select items using a dropdown menu in an Angular application

Let me describe a scenario where I am facing an issue. I have created an HTML table with certain elements and a drop-down list Click here for image illustration When the user selects in, only records with type in should be displayed Another image refere ...