Intelligent-Table: Effectively filtering data by combining various properties within a column

I have integrated a smart table into my Angular project. Currently, I am storing a list of individuals in an array.

$scope.persons = [
    {
        "firstname":"Anders",
        "lastname":"Andersson",
        "city":"Stockholm",
        "country":"Sweden"
    },
    {
        "firstname":"John",
        "lastname":"Smith",
        "city":"Washington DC",
        "country":"USA"
    }
];

These individuals are connected to my table.

<table st-safe-src="persons" class="table">
    <thead>
        <tr>
            <th><input st-search="firstname" class="form-control" type="search"/></th>
            <th><input st-search="lastname" class="form-control" type="search"/></th>
            <th><input st-search="city" class="form-control" type="search"/></th>
            <th><input st-search="country" class="form-control" type="search"/></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in persons">
            <td>{{person.firstname}}</td>
            <td>{{person.lastname}}</td>
            <td>{{person.city}}</td>
            <td>{{person.country}}</td>
        </tr>
    </tbody>
</table>

This setup is functioning smoothly. However, I would like to modify the table by combining two (or potentially more) properties into one column. Specifically, I wish to merge the city and country properties together as shown below.

<table st-safe-src="persons" class="table">
    <thead>
        <tr>
            <th><input st-search="firstname" class="form-control" type="search"/></th>
            <th><input st-search="lastname" class="form-control" type="search"/></th>
            <th><input st-search="???" class="form-control" type="search"/></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in persons">
            <td>{{person.firstname}}</td>
            <td>{{person.lastname}}</td>
            <td>{{person.city}}, {{person.country}}</td>
        </tr>
    </tbody>
</table>

In making this change, I want to be able to search for both the city and country in the third column. What steps do I need to take to implement this functionality?

Answer №1

Here's a unique concept (I believe there are multiple ways to incorporate this type of functionality).

Within a clever table setup, you have the option to create a secure duplicate of the data for any alterations you wish to make without changing the original data by using the st-safe-src attribute. In this protected collection, combine the city and country strings into a new property.

person.location: [person.city, person.country].join(', ');

Alternatively, adjust the table data before sending it to the smart-table

then filter by the newly created 'location' property st-search="location"

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

JavaScript Drag-and-Drop Statement Issues

Currently working on a JavaScript game that utilizes the drag and drop feature of HTML. The goal is to make randomly generated fruit images draggable and droppable onto a jelly image. When the dragged image matches a certain condition (e.g., when the numbe ...

Unusual behavior involving the selection of $stateParams

Seeking a solution for updating angular-ui route parameters based on select field changes. Issue: The route successfully updates with the selected parameter, but the select field does not reflect the change in option selection. Check out the Plunkr. Clic ...

React Native error: encountering the error message "undefined is not an object '_this3.props.navigation()'"

I am encountering an error in the navigationOptions() function when running my React app, but everything is working correctly in the render() function. App.js import React, { Component } from 'react'; import { AppRegistry, View } from 'r ...

Switch the GChart graph type using a button in Vue

<GChart id="theChart" :type="newChartType" :data="chartData" :options="chartOptions()" :resize-debounce="500" :events="chartEvents" ref="gChart" /> < ...

Navigate divs with varying z-index values

I want to change the z-index of 3 divs by toggling them using jQuery, but I'm not sure how to do it. What I want is to click a button that relates to a specific div and increase the z-index of that div so the content inside it is shown. Currently, all ...

data retrieval error using promise

I am struggling to figure out how to use promises effectively. I'm facing an issue with promises while trying to return a new state in the loadPosts function after fetching data from an API: [loadPosts]: (state, index) => { fetchPosts().then(d ...

Mastering the art of scrolling and selecting items concurrently using the mouse in Vue

Struggling with a fascinating challenge of scrolling while selecting items using mouse drag in both up and down directions. Here's a screenshot for reference: https://i.stack.imgur.com/giMwY.png Check out my code: https://codesandbox.io/s/select-i ...

What is the best way to generate script code dynamically on an HTML page depending on the environment?

I am facing a challenge with my asp.net application. I need to insert a dynamic script into the html section, and this script's value must change depending on the environment (TEST, QA, etc.). To illustrate, here is the script where DisplayValue is th ...

Instructions for highlighting a dynamically added UL Li element for a brief 3-5 seconds after clicking a button

When I click a button, I dynamically add UL and LI elements. After they are added, I want to show them highlighted on the user interface for a brief period, like 3-6 seconds. ...

Connecting two sets of data from a mongoDB database using vue.js

Hey there, I'm a newcomer to vue and mongodb. I've set up two collections - one for storing user details and the other for business details. When a business registers through a form, their information is saved in mongodb. Now, I've created a ...

Retrieving the image file from the server and encoding it into base64 with the help of nodejs and express.js

Is there a way to retrieve a specific image file from the server, convert it to base 64, and then store it in a variable without having to loop through the directory to list all files? Note: The goal is to retrieve the exact image file without the need fo ...

Hide all div elements except one by toggling them at the same position

I’m diving into the world of jQuery and facing some challenges with the .toggle() function. My goal is to have multiple <div> elements displayed in the same position, but only one visible at a time. When a new <div> is opened, the previous o ...

What is the best way to tally the frequency of words in a collection of URLs using JavaScript?

I have a JSON object in WordPress that contains a list of URLs. I would like to determine the frequency of occurrence of the second part of each URL. Currently, the code snippet below is able to extract the remaining part of the URL after the prefix https ...

Battle between Comet and Ajax polling

I'm looking to develop a chat similar to Facebook's chat feature. Using Comet would require more memory to maintain the connection. There seems to be a latency issue when using Ajax polling if requests are sent every 3-4 seconds. Considering t ...

JavaScript: "Changing the date string to a different format"

Looking to convert a date string from yyyy-MM-dd HH:mm:ss.SSS in PST timezone to UTC format 2016-07-28T17:22:51.916Z. Any ideas on how to achieve this transformation? ...

Select the first item that is visible and chosen

Currently, I am working with a select list: <option ng-repeat="hour in Hours" value="{{hour.Value}}" ng-show="filterEvent($index)" ng-selected="hour.Value == EventDate || $first"> {{hour.Text}} </opti ...

The XMLHTTPRequest Access-Control-Allow-Origin allows cross-origin resource sharing to

I am attempting to send a request to a PHP file. I collect the longitude and latitude from a function in the Maps API, then use AJAX to store these points in a MySQL database. Using AJAX function savePoint(latitude, longitude){ $.ajax({ ...

Test success despite Cypress assertion failing

Conducting integration tests on an API. Encountering a scenario where one test passes while another fails despite having similar assertions. Feeling confused about the handling of async/promises in cypress. context("Login", () => { // This t ...

Identifying whether a child component is enclosed within a specific parent using React

Is there a more elegant and efficient method to determine if the parent of SeminarCard is Slider? Currently, I am passing this information through a prop. The prop value (true/false) is used to provide additional padding. When used independently: <Semi ...

Ways to attach dynamic methods within a v-for loop

I am currently working on a situation where I need to dynamically assign methods to elements that are being generated by a template using a v-for loop. These methods will be assigned based on the value of a particular variable, specifically the 'btn.m ...