What is the best way to divide an HTML table into two sections?

I'm looking to organize my data into a table with two separate sections, one on the left and one on the right. For example, if I have 20 rows of data, I want to display the first 10 rows on the left side with headers and the remaining 10 rows on the right side with the same header as shown in the image below. Additionally, I would like to implement pagination for both tables. How can I achieve this?

Any help would be greatly appreciated. Thank you in advance.

View Image Here

tableData = [{name:'abc',phone:1111},{name:'xyz',phone:1111},{name:'mno',phone:1111},{name:'pqr',phone:1111}]
<div class="row">
                    <div class="col-6">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th>Name</th>
                                    <th>Phone</th>
                                    
                                </tr>
                            </thead>
                            <tbody>
                                <tr *ngFor="let data of tableData; let i = index">
                                    <td><span>{{i+1}}</span></td>
                                    <td><span>{{data.name}}</span></td>
                                    <td><span>{{data.phone}}</span></td>
                                    
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-6">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th>Name</th>
                                    <th>Phone</th>
                                    
                                </tr>
                            </thead>
                            <tbody>
                                <tr *ngFor="let data of tableData; let i = index">
                                    <td><span>{{i+1}}</span></td>
                                    <td><span>{{data.name}}</span></td>
                                    <td><span>{{data.phone}}</span></td>
                                    
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>

                <div class="row">
                    <div class="col-4">
                        <app-pagination [size]=" (tableData).length " [items]="Items "></app-pagination>
                    </div>
                    
                </div>

Answer №1

Implemented a style using "display:flex" to ensure the two tables are displayed side by side.

To further explore this topic, please visit https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Traversing_an_HTML_table_with_JavaScript_and_DOM_Interfaces

tableData = [{name:'abc',phone:1111},{name:'xyz',phone:1111},{name:'mno',phone:1111},{name:'pqr',phone:1111}]
<div class="row" style="display:flex">
                    <div class="col-6">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th>Name</th>
                                    <th>Phone</th>
                                    
                                </tr>
                            </thead>
                            <tbody>
                                <tr *ngFor="let data of tableData; let i = index">
                                    <td><span>{{i+1}}</span></td>
                                    <td><span>{{data.name}}</span></td>
                                    <td><span>{{data.phone}}</span></td>
                                    
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-6">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th>Name</th>
                                    <th>Phone</th>
                                    
                                </tr>
                            </thead>
                            <tbody>
                                <tr *ngFor="let data of tableData; let i = index">
                                    <td><span>{{i+1}}</span></td>
                                    <td><span>{{data.name}}</span></td>
                                    <td><span>{{data.phone}}</span></td>
                                    
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>

                <div class="row">
                    <div class="col-4">
                        <app-pagination [size]=" (tableData).length " [items]="Items "></app-pagination>
                    </div>
                    
                </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

Verify whether all the elements within a specific div are distinct by utilizing jQuery

I need to create a select box that, when an option is chosen, generates a certain number of textboxes within a div. Currently, there are three fields: display_name[], user_name[], and user_password[] The code for this functionality is as follows: <se ...

Angular: Display an element above and in relation to a button

Before I dive in, let me just mention that I have searched extensively for a solution to my problem without much luck. The issue is describing exactly what I'm trying to accomplish in a way that yields relevant search results. If you're interest ...

Is it feasible to have content wrap around a Grid-Item?

I've been experimenting with the new CSS Grids layout module to arrange my content. I have a set of paragraphs that are 8 columns wide, and I'm looking to insert a figure that spans 3 columns in columns 1-3. After that, I want the following parag ...

Enter the Kannada language into the HTML text box or input field

My html form consists of about 15 - 20 input and textarea fields. As a user, how can I enter information in Kannda or any other local language? https://i.stack.imgur.com/60PVT.png ...

Using Angular 2, NodeJS, and Mongoose to send data from an Angular 2 frontend to a NodeJS backend REST API. However, encountering an issue where the Node API logs show that the OPTIONS

I am facing an issue with sending data from my Angular2 frontend API to the backend client, which is built using NodeJS and mongoose. When I inspect the data being sent on the Angular2 client through console.log, I can see that the correct values are being ...

What advantages does CfnAppSync provide over using AppSync in a CDK project?

We are in the process of enhancing our API by adding new JS resolvers and phasing out the VTL resolvers for an AWS AppSync CDK project, specifically built with Cfn<> Cloud Front CDK. The code snippet below illustrates how this can be achieved: ...

Is the form validation failing to update after an item is removed from the model? Possible bug detected?

Lately, I've been exploring AngularJS and encountered an interesting bug. Let me start by sharing some functional code: View: <body ng-controller="MainCtrl"> <form name="form"> <div ng-repeat="phone in phoneNumbers"> ...

Changing the size of the logo as you scroll through the page

I have implemented the following code to resize the logo as I scroll down the page. $(document).on('scroll', function() { if ($(document).scrollTop() >= 10) { $('.logo img').css('width', '50px'); } else ...

What are some ways to apply separate spans for desktop and mobile devices?

When designing for different devices, I plan to use :span="5" for computers <el-col :span="5" class="container"> and for mobile phones, I intend to use <el-col class="container"> So, how can I incorp ...

Display information from a .js file onto an HTML webpage

I'm completely new to the world of server-side development and I'm attempting to navigate it on my own. Currently, I have a server written in JavaScript using Express and I'm trying to display some content on my HTML page that was sent from ...

Troubleshoot: Python in Databricks Encountering Attribute Error when Sending HTML Emails - 'list' object lacks 'encode' attribute

Looking to send an HTML-formatted email from Databricks using Python, but encountering the AttributeError: 'list' object has no attribute 'encode' error. Despite extensive research through various resources like blogs and stack overflow ...

What could be causing the CSS styling for a Bootstrap 4 button to fail when it's applied?

Starting my first Bootstrap project and running into issues with CSS for my button. Trying to change it to green but it's not working, even though it worked in the past. This is the button I'm trying to style (the blue one): https://i.sstatic.n ...

Determine the `overall` amount and adjust `overall` to equal `quantity * price` within a Typescript

I am looking to perform a calculation similar to this: total = quantity * price and continuously update the total when either the quantity or the price changes. template-output-snapshot app.component.html <form [formGroup]="editform" (ngSubm ...

Is it possible to programmatically trigger the OnChangeFile event in Angular without relying on a button click?

Is there a way to automatically trigger file upload to AWS without having to click the "choose file" button? Here is the code in my .html file: <div class="content"> <input (change)="onChangeFile($event)" type="file&quo ...

What is the best way to reverse an EJS forEach loop?

Here is my ejs code to display images and names from my database. How can I reverse the array order to show the images and names in reversed order? <% posts.reverse().forEach(function(post){ %> <div class="col-md-3 col-sm-6"> ...

Tips for optimizing the performance of nested for loops

I wrote a for loop that iterates over 2 enums, sending them both to the server, receiving a value in return, and then calculating another value using a nested for loop. I believe there is room for improvement in this code snippet: const paths = []; for awa ...

Having trouble with the WordPress style file not functioning properly

I'm currently facing an issue while trying to upload a CSS file and a JavaScript file to a custom theme on WordPress. When I open the webpage, nothing appears and there are no elements displayed. However, when I delete the functions.php file, the webp ...

Trying to implement a sidebar in Django using CSS, but getting no visible results

I tried to replicate a sidebar following the tutorial on codewithtim. Unfortunately, it seems like my CSS code is not being recognized. Here is my home.html: {% extends 'base.html' %} {% block content %} <!DOCTYPE html> <html> < ...

Footer positioned correctly with relative DIV

I find myself in a state of complete confusion. Coding is not exactly my forte, so I suspect I have made a significant error somewhere that is causing the following issue: My goal is to create a sticky footer. The footer does indeed stick to the bottom of ...

Differences between preloading stylesheets and W3C validation explained

I am faced with the challenge of satisfying two different checkers: W3C validator and Google Page Insights Google Page Insight advised me to asynchronously load all blocking CSS files. Therefore, I have modified the stylesheet inclusion by preloading it i ...