Display or conceal information in a distinct container in AngularJS by selecting any cell in a table

In the following demonstration, I am displaying multiple values in a single cell of a table. If a particular row's cell has only one value, there is no action needed. However, if it contains more than one value, we can hide and show these values within the same cell. The hiding and showing actions take place within the same cell.

I would like to achieve this using a separate div. This way, if the number of values exceeds the space in the table cell, it won't affect the layout. Instead, it will expand a separate div to display all the values from that cell.

Please check out the demo – the last row contains multiple values for the ID column. I want this expansion to be displayed in a separate DIV.

View the DEMO

View

<tbody>
      <tr ng-repeat="todolist in todolists">
        <td>
             <span ng-repeat="list in todolist.id| limitTo: showMore ? todolist.id.length:1">
     <a target="_blank" href="{{ 'http://'+common_url}}{{list}}"> {{list}}</a>
 </span> 
     <a ng-show="todolist.id.length>1 && showMore==false" ng-click="showMore = true">....show {{todolist.id.length-1}} more</a>
     <a ng-show="showMore==true" ng-click="showMore = false">....show less</a>
        </td>
        <td>{{todolist.bill_number}}</td>
        <td>{{todolist.location}}</td>
        <td><a target="_blank" href="{{ 'http://' + todolist.url}}">Download Invoice : <i title="Download Invoice" style="padding-left:5px;cursor:pointer;color:black;" class="fa fa-download"></i></a> </td>

      </tr>
    </tbody>
  </table>

Controller

.controller('ctrl', function($scope) {
        $scope.showMore=false;
        $scope.common_url="localhost:8000";
        $scope.todolists = [{
          "id": "id_584",
          "customer_id": 2,
          "url": "url",
          "bill_number": "123",
          "location": "from_location"
        }, {
          "id": "id_122",
          "customer_id": 3,
          "url": "url",
          "bill_number": "123",
          "location": "from_location"
        }, {
          "id": "id_128",
          "customer_id": 4,
          "url": "url",
          "bill_number": "123",
          "location": "from_location"
        }, {
          "id": "id_805",
          "customer_id": 5,
          "url": "url",
          "bill_number": "123",
          "location": "from_location"
        }, {
          "id": "id_588",
          "customer_id": 6,
          "url": "url",
          "bill_number": "123",
          "location": "from_location"
        }, {
          "id":"id_115,id_114,id_116,id_130,id_118,id_119",
          "customer_id": 7,
          "url": "url",
          "bill_number": "123",
          "location": "from_location"
        }]
                $scope.todolists.forEach(function(item){                    
          var multiple_orders = item.id.split(',');
          item.id=multiple_orders;
        });
      });

Answer №1

<td style="word-wrap:break-word">
             <span ng-repeat="item in itemList | limitTo: showMore ? itemList.length : 1">
     <a target="_blank" href="{{ 'http://' + commonUrl }}/items/{{item}}"> <div>
       {{ item }}
     </div></a>
 </span> 
     <a ng-show="itemList.length > 1 && showMore == false" ng-click="showMore = true">....show {{ itemList.length - 1 }} more</a>
     <a ng-show="showMore == true" ng-click="showMore = false">....show less</a>
        </td>

Give this a try!

Answer №2

Update your 'Show More' ng-click event with the following code:

ng-click=" addToDivList(tasklist) "

Define the function as follows:

$scope.addToDivList = function(list){
    $scope.displayInDiv = list;
};

Lastly, connect your div to the displayInDiv variable and display its content accordingly:

<div>
      <a ng-repeat="item in displayInDiv.items">{{ item }}</a>
</div>

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

Tips on how to interact with a hyperlink in Python using a Selenium driver even when the content within the anchor tag is unknown

Utilizing a combination of selenium, phantomJS, and scrapy to scrape javascript content has proven to be an effective method. However, I am encountering an issue where I need to click on a link within a table after the javascript content has loaded. The ch ...

Make sure to always send back JSON data when using the default error handler in ExpressJS

I'm in the process of developing an API server using ExpressJS. I want to guarantee that the server consistently delivers JSON data rather than HTML data. While I can easily make the server respond with JSON for all customized routes, I encounter diff ...

PHP script for conducting sensitivity analysis

I am working with a PHP application that calculates a final result based on user input in multiple forms. Imagine a scenario where a user enters a value of 5 on the first page, which is passed through _POST to the next page. Then, they enter a value of 2 ...

Populate DataTable with HTML content by fetching it through Ajax requests

My goal is to dynamically load the HTML returned from a controller into a div when a user clicks on a row in a table. Check out my code snippet below: // Add event listener for opening and closing details jQuery('#exRowTable tbody').on ...

The textbox is unable to receive input from the pop-up window

Whenever I click on a text-box, a popup window opens up. However, the value is not inserted in the text-box when I select any radio option in the popup. Can you identify where the problem lies? Here's the text-box: <tr><td> Work </td& ...

Guide to displaying the dialogue across the entire application when a button is clicked using React and TypeScript

When clicking on the additem or addbooks button in a React and TypeScript application, I want to display a dialog. The dialog should include a hide button that, when clicked, ensures the dialog will not appear again for the session. Below is the code snip ...

Determine selected option in Radio Button

FORM : <form id="approvalPenambahanUserInt" name="approvalPenambahanUserInt" action="" method="post"> <div class="form-group"> <div class="col-sm-12"> <label for= ...

Scrolling causes the image to blink

I have a specific task to create an effect where an image blinks three times on scrolling (like lights turning on and off consecutively with a 1-second delay), and then stays on until the user scrolls beyond 3600px. To achieve this, I have added an event ...

Guide to positioning a button on top of another button using Vuetify

I'm facing an issue where I want to add a button on a clickable card, but clicking the button also triggers the card click event. Here's my current code snippet: <v-card @click="show = !show"> <v-img src="https://cdn.vuetifyjs.com/im ...

Can Javascript be used to identify the number of td elements in a table and specify column widths within the table tags?

Is there a way to automatically add the "col width" tag based on the number of td tags within a Table tag? For example, if there are 2 td's, then it should add 2 "col width", and if there are 3 then, 3 "col width", and so on. <!DOCTYPE html> &l ...

Tips for implementing validation in AngularJS

Could someone help me with AngularJS validation? I'm new to it and trying to make sure everything is correct. var app=angular.module('myApp',[]) app.controller('myController',function($scope){ $scope.clickMe = function(){ if($(& ...

The Ajax request returned empty data

Is there a problem with retrieving data based on user selection from a drop-down menu in an MVC 5 controller? I am able to capture the selected value, but when passing it to the controller, the data appears to be null. Any suggestions or solutions? jQuery ...

Building a custom search modal using RenderPartial in Yii

I'm currently working on developing a modal box that will enable users to filter and search through a grid. The main objective is to allow users to retrieve information from one database while simultaneously completing a form in another database. Alt ...

Adjusting image dynamically based on conditions

I need to dynamically display images on my HTML based on specific conditions using TypeScript. In my TypeScript file: styleArray = ["Solitary", "Visual","Auditory","Logical","Physical","Social","Verbal",]; constructor(){ for (var i = 0; this.sty ...

The click() function in jQuery is not functioning as expected when linked to an anchor tag generated in PHP

On my website, I have PHP code that generates HTML anchor elements. Here is a snippet of the code: if(!$isOnOwnPage) echo '<a id="message-button" class="button">Message</a>'; if($isOnOwnPage) echo '<a id="add-img-butt ...

Assign an event listener to a collection of elements

Suppose I have an Array containing elements and another Array consisting of objects in the exact same index order. My goal is to add a click event for each element that will display a specific property of each object. For instance: myDivArray = [ div0, d ...

Replace the existing echo statement by refreshing it instead of simply adding a new one

I have developed an input feature that allows users to update their information. The entered data is displayed immediately after the input field, thanks to AJAX integration. I have managed to make everything functional, but I am encountering an issue where ...

The JSON data may be improperly formatted

My script is not functioning correctly, it returns about 20 undefined values before finally displaying the full_name: function retrieveUserInfo(phrase) { $.ajax({ url: 'get_staff_details.aspx?rand=' + Math.random(), type: &ap ...

Creating a webpage header with Javascript to mimic an existing design

I am in the process of building a website with 5 different pages, but I want the header to remain consistent across all pages. To achieve this, I plan to use an external JavaScript file (.js). The header includes the website name (displayed as an image) an ...

Establish a connection using node.js to enable communication between a server and a client

Running a node.js Server:- // *********** Setting up a server to receive orders ************ // // requiring the http module. // var http = require('http'); // initializing request variable as an empty string. // var req = ""; // creating th ...