Tabulator: Adding a new row with merged columns in Tabulator

Is there a method to insert a new row in Tabulator that spans multiple columns?

view image here I am looking for something similar to this, where data is displayed across more than one column.

I need to incorporate additional details retrieved from an ajax call or other functions into a new row with cells spanning multiple columns. These cells may not only contain prices, but also other information. Therefore, no calculations are necessary.

What is the best approach to address this issue? Possibly by adding a footer or utilizing other methods to achieve the desired result.

Since I am working with TypeScript, it would be greatly beneficial if the solution provided is specific to TypeScript.

Thank you very much for your assistance.

Answer №1

To implement this functionality, consider utilizing the rowFormatter feature as shown below.

Note: There might be some unintended consequences when using this method. It's important to disable column resizing for merged columns to ensure proper functionality.

const tableData = [
  { id: 1, name: 'Billy Bob', age: '23', gender: 'male', height: 1, col: 'red', dob: '25/03/2000' },
  { id: 2, name: 'Mary May', age: '41', gender: 'female', height: 2, col: 'blue', dob: '14/05/1982' },
  { id: 3, name: 'Margret Marmajuke', age: '30', gender: 'female', height: 5, col: 'yellow', dob: '31/01/1993' }
]

const table = new Tabulator('#table', {
  layout: 'fitColumns',
  data: tableData,
  columns: [
    { title: 'Name', field: 'name', width: 175, resizable: false },
    { title: 'Age', field: 'age', width: 100, resizable: false },
    { title: 'Gender', field: 'gender', width: 100, resizable: false },
    { title: 'Favourite Color', field: 'col', width: 150 },
    { title: 'Date Of Birth', field: 'dob' }
  ],
  rowFormatter: function (row) {
    const data = row.getData()

    if (data.col === 'blue') {
      const nodes = row.getElement().childNodes
      const [c1, c2, c3, ...remains] = nodes
      const merged = document.createElement('div')
      const mergedWidth =
        parseInt(c1.style.width, 10) + parseInt(c2.style.width, 10) + parseInt(c3.style.width, 10) + 'px'

      merged.style.width = mergedWidth
      merged.className = 'tabulator-cell'
      merged.innerHTML = 'Merged "' + data.name + ' + ' + data.age + ' + ' + data.gender + '"'

      row.getElement().replaceChildren(merged, ...remains)
    }
  }
})
<html>
<head>
  <link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="05716467706964716a772871646769607645302b302b37">[email protected]</a>/dist/css/tabulator.min.css" rel="stylesheet" />
  <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc889d9e89909d88938ed1889d9e90998fbcc9d2c9d2ce">[email protected]</a>/dist/js/tabulator.min.js"></script>
</head>
<body>
  <div id="table"></div>
</body>
</html>

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

Filtering a collection in Firestore using the `where()` method for a context provider in Next.js

i encountered an issue: when using the useEffect function to retrieve my firestore documents, it works well. Currently, I am fetching all "profiles" documents (3 in total). However, I now want to only retrieve the documents where the field "workerProfile" ...

What steps can I take to resolve the issue of item display in the dropdown menu?

My objective is to have a dropdown list with "title 1234" appearing first. When this option is selected, its value should be 1234. How can I achieve this? Here is the desired outcome: https://i.sstatic.net/CqWgn.png Currently, the list looks l ...

What is the process for converting JavaScript into a string using browserify?

Is it feasible to browserify my javascript code before transmitting it to the browser? Is there a method to provide the javascript as a string in browserify? For instance: browserify("let a =1; console.log(a)"); I have accomplished this by specifying a JS ...

Issue with Ionic app causing code execution to hang when the Back Button is pressed

I am currently working on an application using Ionic and React. There is a page in the app where users can upload images from the camera or gallery, which are then saved as binary data in a database (indexed db using Dexie). Everything seems to be function ...

Utilizing the JavaScript map method to structure API response data

Here is the JSON data I have: { "result": [{ "name": "a", "value": 20, "max": 100, "sale_value": [{ "no": 1, "name": "aaaaa", "price": 200 }, { "no": 2, ...

Is it beneficial to disable and deactivate Validators in Angular?

Within our Angular framework, we've implemented a form with 10 fields. However, a new requirement has surfaced where certain individuals only require access to specific fields out of the existing 10. To accommodate this, our team is currently addressi ...

Form submissions are not saving checkbox answers

As a beginner, I'm struggling to save the checkbox answers on the page after submission. The code below is quite lengthy (checkboxes start at 314). I have a feeling that I might be missing a piece of code, but I just can't seem to pinpoint what i ...

Discover supplementary characters to incorporate into a JavaScript string

I am facing a challenge with identifying three added characters in the second string that are not present in the first string. These added characters could be located anywhere within the string. For example: string1 = "hello" string2 = "aaahello" // =&g ...

What is the reason behind my page being redirected by an alert?

What could be causing the page to redirect to its PHP script every time an alert is added to my AJAX form, but not redirect when the alert is removed? I want to prevent the page from redirecting to the PHP script. $(document).ready(function(){ ...

Managing Models in THREE.js

My current project involves loading .obj files using THREE.OBJLoader() and then adding each object to the screen by pushing it into the myObjs[] array. var myObjs = []; var loader = new THREE.OBJLoader(); loader.addEventListener( 'load', functio ...

A TypeScript/Cypress command that restricts input parameters to specific, predefined values

I have a Cypress command with a parameter that I want to restrict so it only accepts certain values. For example, I want the columnValue to be limited to 'xxx', 'yyy', or 'zzz'. How can I achieve this? Cypress.Commands.add( ...

Fetching various data from MongoDB using NodeJS and presenting it in Jade(Pug) template

I am working with MongoDB collections and need to showcase them on my website, creating a dynamic page that updates automatically. Specifically, I am dealing with team members' information in the database. Here is an example of how my collections loo ...

Leverage the camera functionality in both native and web applications using Ionic/AngularJS and Cordova

Could you provide some guidance on how to use the Camera feature in both web and native environments? I have tried implementing it using the code snippet below, taken from ng-cordova documentation: $scope.takePicture = function() { var options ...

Sending a POST request from a React child component to an Express server

I recently started working on a project using the MERN stack, incorporating react-router and redux. Within my application, I have integrated a <Navbar /> component along with a <SearchBar> component. To manage the react side of things, I utili ...

React : understanding the state concept as written like ...state

As I explore React, can you please explain the significance of this piece of code to me? const new_venues = this.state.venues.map((venue) => place_id === venue.place_id ? { ...venue, open : !venue.open } : { ...venue, open: false }); I understand the ...

Why won't my JavaScript addEventListener activate on form submission?

I have a basic question as a beginner in JavaScript. I am facing some challenges with my first task involving JavaScript. I decided to learn JS by creating a TODO List, but I am stuck right at the beginning. The event listener that should respond when the ...

Finding a solution for the network error encountered during the execution of XMLHttpRequest.send in the specified file path (...distfxcoreservermain.js:200

Having recently delved into Angular, I successfully completed the development of my angular web application. While using ng serve for production, everything ran smoothly. However, after incorporating angular universal and attempting npm run dev:ssr or np ...

What is the best way to retrieve the duration of an object tag using JavaScript or jQuery?

My goal is to determine the duration and length of only mp4 type videos. Although I used the video tag to retrieve these values, it does not support mp4 files. Despite several attempts, I was unable to get the video tag to play only mp4 files, as it stric ...

Showing information retrieved from an API and rendering it on an HTML page

My aim is to showcase a list of calculated results fetched from a local server. In the console, this data appears as an array of objects, but on the webpage, it is being displayed as separate string characters for each li element. How can I display the con ...

AngularJS: Issue with directive function not being executed

I created a directive in my code, but for some reason the function I provided to define the directive is not being called. It was working perfectly fine before, and now it just suddenly stopped without any clear explanation. Below is the code snippet of m ...