Foldable Table with Editable Features

I'm currently working on a table, and I would like to make it collapsible as well as editable. However, I've been having trouble achieving both functionalities simultaneously. The table in the provided link is exactly how it should look, and the editable JavaScript is functioning correctly. Now, I just need guidance on how to collapse the rows. For instance, collapsing all sub-items 1 under Item 1 or collapsing all sub-items under Item 3.

<html>
<style>
* {
    margin: 0;
    padding: 0;
  }

  .grid {
    display: grid;
    grid-template-columns: 30px auto 15px;
    grid-template-rows: 40px auto 20px;
    grid-template-areas: 
    ". title ."
    ". header ."
    ". content ."
    ". footer .";
    grid-gap: 5px;
  }
  .title {
    grid-area: title;
   
  }
  .header {
    grid-area: header;
    place-self: left;
    font-family: Montserrat, sans-serif;
    font-size:50px;

  }
  
  .content {
    grid-area: content;
    display: grid;
  }
  .footer {
    grid-area: footer;
    
  }
  </style>

The jquery.tabledit.js file is too big to include here, but you can find it described in the JSFiddle link :-).

Answer №1

Kindly complete the javascript comment. Change it from

<!--Script to collapse rows

to

<!--Script to collapse rows-->

Additionally, since both parent rows have the same id, clicking on one parent row will cause both parent rows to expand or collapse together. Assign different ids to each parent row and use classes for child rows like this:

for Parent rows

<tr class="parent" id="row1">

<tr class="parent" id="row2">

and for child row

<tr class="child-row1" style="display: table-row;">

<tr class="child-row2" style="display: table-row;">

Answer №2

To resolve the issue at hand, I implemented an expand/collapse feature using CSS and JS without relying on any external libraries. Here is the updated solution along with a link to the jsfiddle [https://jsfiddle.net/elalex78/zkxdc1jo/]. Additionally, here is the additional code snippet for achieving pure collapse and expand functionality.

<tr class="header expand">
        <td>1</td>  
        <td>6010230</td>  
        <td><button type="button" class="fa fa-minus btn btn-danger"></button><button type="button" class="fa fa-plus btn btn-success"></button></td> 
    </tr>  
    <tr>    
        <td>1.1</td>   
        <td>1023526</td>     
        <td><button type="button" class="fa fa-minus btn btn-danger"></button><button type="button" class="fa fa-plus btn btn-success"></button></td> 
    </tr>  
<tr class="header expand">  
        <td>2</td>  
        <td>6010230</td>  
        <td><button type="button" class="fa fa-minus btn btn-danger"></button><button type="button" class="fa fa-plus btn btn-success"></button></td> 
    </tr>  
    <tr>    
        <td>2.1</td>   
        <td>1023526</td>     
        <td><button type="button" class="fa fa-minus btn btn-danger"></button><button type="button" class="fa fa-plus btn btn-success"></button></td> 
    </tr>  

For CSS styling, only pointer and bold properties were applied.

tr.header
{
  font-weight: bold;
  cursor: pointer;
}

The following script handles the collapse/expand functionality:

//script for collapse/Extend

$('.header').click(function(){
     $(this).toggleClass('expand').nextUntil('tr.header').slideToggle(100);
});

All other CSS configurations for the table will be preserved as is.

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

Revise website design to adjust dynamically according to screen dimensions

Currently, I am working on a school project with a website created by former students. Unfortunately, I have limited knowledge of HTML and CSS which has made it challenging for me to ensure the site is mobile-friendly. There are issues such as text overflo ...

Having trouble with loading base.css in React tutorial?

Struggling with the React tutorial here. Managed to get the server/API up and running thanks to stackoverflow, but now I'm facing an odd issue - base.css won't load. The base.css file is sitting right where it should be in the css folder, and we ...

Creating dynamic menu elements in HTML

How can I create movable menu items in HTML? Currently, I have four menu items arranged vertically in the right corner of my site like: Home Services Contact About I would like to make it so that when the user clicks on a menu item, it moves to the top ...

customized format for API response

Trying to inspect SSL certificate data using php curl, but the data returned is a jumble of HTML format according to firebug. Below is a snippet of the output: HTTP/1.1 200 OK Date: Mon, 13 Apr 2015 14:10:05 GMT Server: Apache Set-Cookie: v1st=9C74FC61 ...

What steps should I take to ensure a local HTML page retains the current section that is hidden open whenever it is reloaded?

One of the challenges I have encountered with my local HTML note-taking file is that, despite dividing it into hidden sections accessible by clicking on buttons at the top of the page, reloading the content resets it back to its default state. This means t ...

What steps can I take to alter this situation?

I am working on creating an API Code. Here is the code I have written: When we run the code, it displays as follows: website <?php include('simple_html_dom.php'); $url = 'https://www.g2g.com/wow-us/gold-2299-19249?&server=30805&a ...

HTML - Using Tables to Add and Edit Rows

Take a look at this demo on JSFiddle for my project: Demo jsfiddle I'm currently in the process of creating a table with various functionalities. The function "sortTable" is responsible for sorting the table and it's functioning as expected. T ...

What is the best way to align text on both the left and right sides of a mat-card-header in Angular

I'm struggling to align text content in the header on both left and right sides of the header tag. I've tried various approaches, but none seem to work for me. Can someone please help? <div style="width: 40%"> <mat-card> <m ...

Chrome Browser: Issue with CSS and JavaScript transitions not functioning correctly

I have three images named img1, img2, and img3. Initially, their position is set to -50% absolute top right and left. When I change the position to static with a transition of 2s, they should move to the center. Issue: During the transition, there is snap ...

Using jQuery to serialize AJAX requests with variables

I've encountered an issue with submitting a form using jQuery ajax after validation checks. Strangely, when I use a variable for the form ID in the data parameter, the form data fails to submit. However, if I explicitly specify the form ID, the submis ...

parent div with overflowing height

I am working with 2 tabs, each displayed as flex. My goal is to have a scroll bar appear only on the list within #myTabContent if it overflows .main-panel due to the content, rather than having a scroll bar on the entire div. This way, #myTabContent should ...

Tips for aligning the TextBox in the center of an Asp.net website

I have the following HTML/ASP code that I need to center the TextBox on the display page. Here is my code snippet below. Ideally, I would like to have the label displayed next to the TextBox once it is centered. <center> <div class="container ...

Is it possible to combine Ajax, JS, HTML, PHP, and MySQL in a single project?

I am looking to create a web application and wondering if I can integrate Ajax, JavaScript, HTML, PHP, and MySQL all together? ...

Tips for directing attention to a div element

Need some help here! I'm just starting out with JS and jQuery, so please be gentle. Is it possible to set focus on a div element? I am looking to trigger events when the div is clicked or focused, as well as when clicking outside of the div. Here&apos ...

Bootstrap Datepicker, ensuring error-free date selections for check-in and check-out dates

I have encountered some issues while using the bootstrap date picker. If you visit this website, you will find an example of a check-in and check-out selector. When I choose Feb 8th as my arrival date and Feb 9th as my departure date, and then go back to ...

Crafting a stylish vertical timeline using Tailwind and CSS: Step-by-step guide

I am attempting to design a timeline for a react app where odd children are displayed on the left side of the timeline and even children on the right side. Here is an image for reference: https://i.sstatic.net/YnNFU.png The issue I am facing is that I am ...

A step-by-step guide on showcasing a list of data in Select2 jQuery plugin and retrieving relevant information

After converting my data into JSON format, I am trying to display it in a select element so that I can easily search for specific data based on input. This is the function in my controller: $response = $this->GET(config('constant.url').&apos ...

What makes Django forms the better choice over HTML forms?

Greetings! As a beginner in the world of Django, I am currently struggling to grasp the concept of Django forms. I find myself questioning the utility of Django forms when we already have the option to use HTML forms. Can someone please clarify this for ...

Struggling to create a 3x4 grid using Bootstrap - any tips?

I am attempting to design a grid layout for displaying 12 images in a squared items format. My initial idea was to create a grid with 4 rows and 3 columns, but I have been unsuccessful in my attempts so far. Despite searching for tutorials and guides, I ha ...

Determine the DOM element that corresponds to a right-click action

I utilized the code snippet below to construct a personalized context menu: <script type="text/javascript"> $(document).ready(function() { var x, y; document.oncontextmenu = function(e) { e.preventDefault(); x = e.clientX; ...