Combine information within a designated column

I am facing an issue with the table structure below:

<table class="table main-table" ng-if="linesArray && linesArray.length > 0">
    <!-- HEADER-->
    <thead class="table-head">
        <tr>
            <th ng-repeat="column in ::columns" width="{{::column.width}}">{{::column.label}}</th>
        </tr>
    </thead>
    <!-- BODY -->
    <tbody>
        <tr ng-repeat="line in linesArray">
            <td ng-repeat="column in ::columns" width="{{::column.width}}" ng-class="{
          'center-text' : (!line[column.key] || line[column.key].length === 0)
        }">{{line[column.key] !== undefined ? line[column.key] : '--'}}
            </td>
        </tr>
    </tbody>
</table>

Here is how it appears when rendered:

https://i.sstatic.net/MJoXT.png


The Goal I'm Striving For:

I aim to combine the data from two distinct fields into a single column, resulting in something like this:

https://i.sstatic.net/OJMBy.png

In the example above, the column displays date and time information with specific formatting.

The directive responsible for managing the table logic:

function historicalSummaryTable($filter) {
    return {
        restrict: 'EA',
        link: link,
        templateUrl: 'jfrontalesru/app/components/historicalSummary/historicalSummaryTable.html',
        scope: {
            linesArray: "=",
            columns: "=",
            groupField: "@",
            groupFieldFilter: "@",
            groupFieldFilterFormat: "@"
        },
    };

    function link(scope, element, attrs) {
        var _groupField = 'groupField';
        var _subgroupField = 'subgroupField';

        scope.$watch('linesArray', function(value) {
            scope.linesArray.forEach(function(line) {
                // Apply filter for each column if set
                scope.columns.forEach(function(column, index) {
                    // Apply the filter
                    if (column.filter && column.filter.length > 0) {
                        line[column.key] = $filter(column.filter)(line[column.key], column.format);
                    }
                });
            });
        });
    }
}

This directive formats the input date data and then passes it through the controller as shown below:

  vm.historicalColumns = [
     {label: $translate('columnDateTime'), key: "timestamp",width:"18%", filter:"date",format:"mediumTime", group:false},
     {label: $translate('columnDetails'), key: "detail",width:"50%", group:false},
     {label: $translate('columnOrigin'), key: "origin",width:"17%", group:false},
     {label: $translate('columnUser'), key: "user",width:"15%", group:false}
];

I am unsure of how to achieve the desired result, any guidance would be appreciated.

Answer №1

If you want to differentiate the first column in a table, consider using a span element with an ng-if directive that checks the index value:

 <td ng-repeat="column in ::columns" width="{{::column.width}}" ng-class="{
          'center-text' : (!line[column.key] || line[column.key].length === 0)
        }">
      <span ng-if="$index==0">first column only</span>
      {{line[column.key] !== undefined ? line[column.key] : '--'}}
</td>

Alternatively, you can preprocess your data in the controller and concatenate the necessary values before displaying them in the table.

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

Obtain Image in PNG Format using an AJAX Call

I received an Image/PNG from my python service, and it looks like the following: PNG IHDRX,(ã=¤tEXtSoftwareAdobe ImageReadyqÉe< iTXtXML:com.adobe.xmp<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:met ...

The type '{}' is lacking the 'submitAction' property, which is necessary according to its type requirements

I'm currently diving into the world of redux forms and typescript, but I've encountered an intriguing error that's been challenging for me to resolve. The specific error message reads as follows: Property 'submitAction' is missing ...

What is the best way to extract JSON data from a remote URL?

Having recently started with JavaScript, I am looking to parse JSON from an external URL using pure JavaScript. Currently, I have the following code: var getJSON = function(url, callback) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, tr ...

Consecutive AJAX requests triggered by previous response

While there are numerous resources available regarding making synchronous AJAX calls using deferred promises, my specific issue presents a unique challenge. The process I am attempting to facilitate is as follows: Initiate an AJAX call. If the response i ...

Dealing with a null array triggering the error message "Uncaught (in promise) SyntaxError: Unexpected end of JSON input."

My react / redux / node express app is designed to manage patient information, but I'm facing a bug when trying to read new data after deleting a patient encounter. Everything works smoothly until the last encounter associated with the patient is dele ...

Modifying Owlcarousel 2 settings post initialization

I've encountered an issue with the settings of a carrousel plugin I'm using. I've tried to change the loop and nav options but it doesn't seem to be working. Here is the code snippet: var owl = $(".owl-carousel").owlCarousel({loop: tru ...

Using jQuery to verify the presence of an element, especially one that may have been dynamically inserted via AJAX

I have a good understanding of how to verify elements that are present when the document is loaded: jQuery.fn.exists = function () { return jQuery(this).length > 0; } However, this approach does not detect elements that are dynamically added via A ...

How to selectively load specific scripts in index.html with the use of angular.js

Let me address a problem I'm facing with a large development project. It seems that the current setup does not function properly on Internet Explorer. My idea is to only load files that are compatible and do not generate errors when accessed through I ...

How to Pass and Execute Asynchronous Callbacks as Props in React Components

I'm curious about the correct syntax for passing and executing async calls within React components. Specifically: Many times, I'll have a function that looks like this: const doAsync = async (obj) => { await doSomethingAsync(obj) } ...and ...

Obscure Promise Structure - Accomplish, Flop, Achieved

I came across the following code block and I'm struggling to understand it. While I have a good grasp on promises in the context of: deferred.then(successCb, errorCb); This code snippet appears to have three callbacks (complete, fail, done>) whic ...

Updating information within AngularJS select boxes

On my page, I have 3 select boxes. When a user selects an option in the first select box, I want the options in the second select box to update based on the value selected in the first one. Similarly, I want the options in the third select box to change w ...

Is there a delay in Javascript identifying user existence when retrieving values from ajax?

I'm working on a script that checks if a username already exists before allowing a visitor to proceed. Here's a snippet of the code I'm using: EDIT: I've made some adjustments based on your feedback, but I'm still having trouble g ...

Data sent as FormData will be received as arrays separated by commas

When constructing form data, I compile arrays and use POST to send it. Here's the code snippet: let fd = new FormData(); for (section in this.data.choices) { let key = section+(this.data.choices[section] instanceof Array ? '[]' : '& ...

Generating a three-level unordered list using arrays and for-loops in JavaScript/JSON

Are there more efficient ways to achieve the desired results from this JSON data? Can someone assist me in understanding why it is working and if it can be optimized for cleanliness? <div id="accordion" class="display-data"> ...

Obtain the response body in Nest JS middleware

Currently, I am working on developing logging middleware for my project. My main goal is to log the response body specifically in 500 responses. However, I have encountered an issue where the response body is not present in the Response object when using a ...

Getting the id of a row from a v-data-table in VueJs

I am currently facing an issue with retrieving the id of a specific field from each row. I require this id as a parameter for a function that will be utilized in an action button to delete the row. Here is how my table template appears: <template ...

Deselect all checkboxes other than the daily selection

I recently designed an E-commerce website that includes a package customization feature where users can modify their packages. The initial question presents three radio button options: 1. Daily 2. Weekly 3. Monthly If the user selects 'daily&apos ...

Enhancing performance by dynamically updating DOM elements when they come into view during scrolling

Currently, I am in search of an efficient algorithm to dynamically load background-images for a group of <li>'s but I am encountering some efficiency issues. The code I am using at the moment is as follows: function elementInView($elem, vps, vp ...

The combination of Ajax, JavaScript, PHP/HTML, and dynamic variables

Hey there, I'm currently working on a game development project and have encountered what seems to be a scope issue. The issue arises in my js file when a player clicks on the card they want to play: It starts in my js file:</p> <pre>&l ...

When a form contains a ViewChild element, changes to the ViewChild element do not automatically mark the

Let's set the stage: MainComponent.html <form #someForm > <input type="text" name="title" [(ngModel)]="mainVar" /> <child-component /> <input type="submit" [disabled]="someForm.form.pristine" /> </form> ChildComp ...