Tips for arranging my list within my list-group-items to create a visually appealing layout

I've encountered an issue where the alignment of list-group-items inside a card container is not correct. I am using Bootstrap 4 and my aim is to neatly align all 3 fields in a tabbed column layout. Any suggestions on how to achieve this are welcome.

To separate the fields, I have used a | symbol. Below is the code snippet of what I have implemented so far:

<!--HTML-->
<body>

<div class="containers">
  <div class="container-fluid">
    <div class="row">
      <div class="col-6">
        <div class="card">
          <div class="card-header py-2">Testcases</div>
          <div id="rightContainer" class="list-group" style="height:425px; overflow-y: scroll">
            <!--Populated by JS function -->
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

</body>

Additionally, here is the script that populates the above card container. The script utilizes a success function to fetch data from the backend via AJAX and update the container dynamically:

<!--SCRIPT-->

<script>
  function populate_rightcontainer(response) {
    $("#rightContainer > a").removeClass("active");
    $("#rightContainer > a").hide();
    $("#rightContainer").empty();
    for (i = 0; i < response.length; i++) {
      var str = response[i].replace(/\s+/g, "");
      var arr = str.split("|");
      var testcase = arr[0] + "  |  " + arr[1] + "  |  " + arr[2];
      if (arr[2] == "Passed") {
        $("#rightContainer").append('<a class="list-group-item list-group-item-success py-0">' + testcase + "</a>");
      }
      if (arr[2] == "Failed") {
        $("#rightContainer").append('<a class="list-group-item list-group-item-danger py-0">' + testcase + "</a>');
      }
    }
  }
</script>

The current display does not look very appealing and I would appreciate any guidance or modifications to improve the alignment of columns within the container.

You can access a Plnkr demo of my code here:

http://plnkr.co/edit/EumtRHhzNb4nEFhScWjY?p=preview

P.S: On attempting to split by |, I faced issues with spaces which affected my timestamp organization as shown in the image above. Any assistance in resolving this matter would be greatly appreciated.

Answer №1

It is not feasible to achieve what you desire using CSS alone; HTML is required for the task. Have you considered reconstructing it as a real table instead?

Perhaps something along these lines:

<table>
  <tr class="red">
    <td>
      <a href="#">arr[0]</a>
    </td>
    <td>
      <a href="#">arr[1]</a>
    </td>
    <td>
      <a href="#">arr[2]</a>
    </td>
  </tr>
</table>

Check this out:

For HTML:

<table id="rightContainer" style="height:225px; overflow-y: scroll">

Regarding JS:

function populate_rightcontainer(myJSON){
    $("#rightContainer").empty();   
    var data = myJSON.data;
    for(i=0; i<data.length; i++){
        var str = data[i].replace(/\s+/g,'');
        var arr = str.split('|');
        var row = $('<tr></tr>');
        var elementOne = $('<td>' +arr[0] + '</td>');
        var elementTwo = $('<td>' +arr[1] + '</td>');
        var elementThree = $('<td>' +arr[2] + '</td>');
        row.append(elementOne);
        row.append(elementTwo);
        row.append(elementThree);
        $("#rightContainer").append(row);               
        if(arr[2] == "Passed"){
            row.addClass('list-group-item-success');
        }
        if(arr[2] == "Failed"){ 
            row.addClass('list-group-item-danger');
        }
    }
}

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

Utilizing a TypeScript function to trigger an action from within a Chart.js option callback

Currently, I am utilizing a wrapper for Chart.js that enables an animation callback to signify when the chart has finished drawing. The chart options in my code are set up like this: public chartOptions: any = { animation: { duration: 2000, ...

issue with react-adsense leading to numerous problems

I am currently working on integrating AdSense into my React application, but I am facing challenges in understanding the process. Despite going through the documentation for npm react-adsense, I am still confused about where exactly to place the ad code. H ...

Tips for hiding a sidebar by clicking away from it in JavaScript

My angular application for small devices has a working sidebar toggling feature, but I want the sidebar to close or hide when clicking anywhere on the page (i.e body). .component.html <nav class="sidebar sidebar-offcanvas active" id="sid ...

When should we utilize the React.Children API in React applications?

Exploring the potential use cases of the React.Children API. The documentation is a bit confusing for me (Using React v.15.2.0). https://facebook.github.io/react/docs/top-level-api.html#react.children According to the documentation, this.props.children ...

triggering e.stopImmediatePropagation() within an onclick event handler

Is there a way to retrieve the event object from an onclick attribute? I attempted the following: <a href="something.html" onclick="function(e){e.stopImmediatePropagation();}">Click me</a> In addition, I tried this: <a href="something.ht ...

How can I use jQuery to display a div alongside the element that is currently being hovered over?

Imagine having multiple divs similar to these: UPDATE: <div class="ProfilePic"> <a href="#"> <img src="lib/css/img/profile_pic1.png" alt="" class="ProfilePicImg"/> </a> <div class="PopupBox" style="display: ...

Connect the CSS active state to a JavaScript event

.el:active{ background:red; } Is there a way to associate the above CSS active state with a JavaScript event, like this: $('.el').on('active', function(){ img.show(); }); I want the image to remain visible when el is presse ...

The error with Bootstrap4 alpha6 modal is in the process of transitioning

Currently, I am facing an issue with the bootstrap4 alpha 6 modal. The error message I am receiving is: Error: Modal is transitioning This occurs when attempting to re-trigger the same modal with dynamic data using a JavaScript function like this: funct ...

Is there a way to determine the app bar height within a React Material UI application?

I'm trying to create a full-screen image for the opening of my website using React and Material UI. Here's a snippet of my JSX code with the default Material UI theme: <AppBar> //code in between </AppBar> <Container sx={{margin: ...

Steps for preventing form submission when the username is unavailable

After checking the availability of the user name, I encountered an issue where the form still gets submitted even if the username is not available. Updated Code: <SCRIPT type="text/javascript"> $(document).ready(function(){ $("#emailch").change(fu ...

Having trouble inputting text into input field using ReactJS

I am currently facing a challenge while attempting to modify the value of an input field using ReactJS. The issue I am encountering is the inability to input values into the field. After reviewing several other queries, it appears that simply changing the ...

The plus sign ('+') fails to be matched by the regular expression in Angular 2, although it functions correctly in other testing environments

Check out this code snippet: export const PASSWORD_PATTERN: RegExp = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9`~!@#$%^&*()\-_+={[}\]|\\:;"'<,>.?/]{8,}$/; This constant is utilized in the following manner elsewhere: ...

The code functions perfectly on the local server, but encounters issues on the hostinger hosting service - after dedicating 3 days to researching online and numerous unsuccessful attempts

[SCREEN SHOT ERROR 500 APPEARS EVEN AFTER FIXING THE PATH IN AJAX CODE] Uncertain if the issue lies in the ajax call or the path of resource files (jquery) HEADER, I ATTEMPTED TO USE MVC WHERE THE INDEX PAGE CONTAINS PATHS TO ALL PAGES, HEADER, FOOTER, CO ...

Validating the length of form inputs and selected items from a dropdown menu

I have the following form and I am attempting to validate its states as follows: themeName is required and should have a minimum of 4 characters. themeLangFrom selected value cannot be the same as themeLangTo (and vice versa). I want to display a span er ...

Aligning thumbnail images in a jQuery Mobile listview

Hey, I recently added a list view that includes thumbnails. I used the following code: <ul data-role="listview" data-inset="false" data-theme="a" data-dividertheme="d> <li><a href="image.php?imgid=2"> <img src="../images/comma. ...

What steps can be taken to enlarge the select button within a <select> field?

Is there a way to enlarge the size of the downward-pointing arrow button within a <select> element? Here is an example of what my code looks like: <select> <option>Select City</option> <option>City1</option> <o ...

How to prevent selecting a particular date in React-datepicker?

Hey there, I'm new to Stack Overflow and I'm facing a challenge that I hope someone can help me with. I'm currently working on a project where the previous developers used a React datepicker. The project managers want to keep it, but I need ...

How can I prevent Firebase from listening to changes in Framework 7 Vue when navigating between pages?

Assume I have a page called pageA where I am monitoring changes to a firebase document. export default { mounted() { this.$f7ready(() => { this.userChanges(); }) }, methods: { userChanges() { Firebase.database().ref(' ...

Why is my Typescript event preventDefault function ineffective?

Despite all my efforts, I am still unable to prevent the following a tag from refreshing the page every time it's clicked. <p> <a onClick={(e) => handleClick} href="&qu ...

Tips for showing validation message just one time along with multiple error messages

Exploring ways to implement a dynamic form submit function using jQuery. $('#btnsumbit').click(function() { $('.required_field').each(function() { if ($(this).val() == "") { alert('please fill field'); ret ...