How can you send query parameters to ajaxResponse in Tabulator 5.0 while using setData?

I'm currently facing an issue with utilizing both ajaxResponse and setData for a Tabulator 5.0 table. It seems that my URL parameters are disappearing somewhere in the process. When I log the value of params to the console in the code below, it appears as an empty object.

The reason I am using ajaxResponse is because the specific portion of the response I need is nested under "results". Additionally, I am leveraging setData as I intend to dynamically call it multiple times while changing the parameters.

var table = new Tabulator("#my-tabulator-table", {
     ajaxResponse: function(url, params, response){
          console.log(url);
          console.log(params);
          return response.results;
     },
});

var columns = [
    {title: "id", field: "id", headerFilter: false, visible: true, download: true},
    {title: "field1", field: "field1", headerFilter: true, visible: true, download: true},
    {title: "field2", field: "field2", headerFilter: true, visible: true, download: true},
    {title: "field3", field: "field3", headerFilter: true, visible: true, download: true},
];
var url = "/api/v1/myendpoint";
var params = {"param_name": "abc"};

table.on("tableBuilt", function(){
     table.setColumns(columns);
     table.setData(url, params);
});

My main challenge lies in figuring out how to correctly pass the "params" so that they are included in the URL for the ajax query call. Any suggestions on solving this?

Answer №1

When you want to load the initial data in the table, there is no need to manually call certain functions. Instead, you can utilize the ajaxURL and ajaxParams options in the table constructor to automatically trigger the initial ajax request when the table loads.

var table = new Tabulator("#example-table", {
    ajaxURL:"/api/v1/myendpoint, //ajax URL
    ajaxParams: {"param_name": "abc"},
});

To define your columns, you can also use the columns option like this:

var table = new Tabulator("#example-table", {
    columns:[
        {title:"Name", field:"name", sorter:"string", width:200, editor:true},
        {title:"Age", field:"age", sorter:"number", hozAlign:"right", formatter:"progress"},
    ],
});

If you plan to call the setData function later on, follow the correct example. There was an issue with parameters in the initial 5.0 release, but it has been fixed in a subsequent patch release.

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

Karma is unable to locate the module within the specified relative path

I'm facing a challenge with Karma not being able to load a specific file. As a novice in Karma, I dedicated the entire day to researching and checking documentation for similar issues with no luck. Upon initiating the karma process, it encounters an ...

Transform the dataUrl into a blob and send it via ajax request

I am currently utilizing the imgly image cropper plugin with some modifications for my application. It has the ability to convert an image into a dataUrl and produce the image as a base64 image which can then be saved as a jpeg. My objective is to adjust ...

Tips and tricks for displaying JSON data in Angular 2.4.10

In my Angular project, I am facing an issue while trying to display specific JSON data instead of the entire JSON object. Scenario 1 : import { Component, OnInit } from '@angular/core'; import { HttpService } from 'app/http.service'; ...

Utilizing jQuery to load content into the parent of an iframe

I am encountering an issue with a form that submits to an iframe, which then processes a coldfusion page. The coldfusion page is responsible for adding attachments to an item in Oracle based on the form input. There is a div labeled 'testing' tha ...

Retrieve custom attributes of child elements using jQuery selectors

I am looking to modify the data-answersetid attribute of all child controls under the .cloneable class in a table. Each row in the table contains a single control - either a textarea, checkbox, radio button, or input[type=number]. Each control has a custom ...

Is it possible to use AJAX in JavaScript to dynamically update page titles?

When loading a new page using AJAX, I am having trouble updating the title. The expected titles should be "Home", "About", and "FAQ". I attempted to solve this by changing the title with the code snippet below, but it only resulted in displaying "undefine ...

Is there a compelling case for implementing Meteor in 2017?

Back in the day, Meteor was expected to revolutionize web development on node by simplifying the process of creating interactive applications. Though I'm not well-versed in its history, it seems like most of the development effort has shifted elsewher ...

How can I delete an individual HTML element that does not have a class or ID?

I am currently working with a theme that cannot be altered due to automatic update requirements. The theme includes the following HTML code snippet: <div class="dropdown-menu"> <a href="#">Profile</a> | <a href="#">Logout</a> ...

Prevent the ability to drag and drop within specific div elements

Having trouble disabling the sortable function when the ui ID is set to "comp". Can't figure out what's going wrong, hoping for some assistance here. $(".sort").sortable({ // start sortable connectWith: ".sort", receive: function ...

Manipulate the contents of an HTML class using Javascript to substitute text with an empty string

Is there a way to create a JavaScript function that can remove text upon clicking from multiple HTML fields with the same class? I am facing an issue where my function is not clearing the data in the target field when "Yes" is selected in the trigger. Re ...

Sort an array by mapping it in decreasing order based on the total sum of its elements

I came across a JSON structure that looks like the following: { "user": [ {"username": "x1", "pfp": "", "scores": [{"easy": 10, "normal": 1, "hard": 2, "oni&q ...

Leveraging numerous identifiers in jQuery

I created a small jQuery script to check if the input box value is greater than 5, but I have two tags with IDs and only one of them seems to be working. <div id="register"> <form id="register"> <input id="first" type="text" /> <a ...

Convert web address object to URL string

Currently, I am dealing with a stringified object stored in my localStorage, const stringifiedURLObject = fromLocalStorage I have attempted to parse this string using JSON.parse to obtain a normal Url Object. Now, I am looking to convert this object int ...

Upload files via Ajax request is required

I am in the process of trying to upload a binary file to a server while avoiding a full page refresh when the server responds. I must admit, I am not well-versed in this area and I understand if my approach needs some adjustments. This is how I have appro ...

Node.js backpressure with RXJS and PostgreSQL

New title: How can I manage the speed of PgSQL results streaming in JavaScript? Running into memory problems with nodejs v4.5.0 using RXJS(5.4.0) and PostgreSQL (driver "pg": "6.1.4"). I've taken matters into my own hands by manually creating an obs ...

Prevent tooltips from disappearing when hovering over them

I need assistance in keeping my tooltip visible when the mouse is on it, but hiding it when the mouse moves out. Can you please help me achieve this? $(document).ready(function(){ $('[rel=tooltip]').bind('mouseover', function() { ...

Using .htaccess file to optimize SEO crawling for single page applications that do not use hashbangs

When using a page with pushState enabled, the typical method of redirecting SEO bots involves utilizing the escaped_fragment convention. More information on this can be found here. This convention operates under the assumption that a hashbang prefix (#!) ...

Issue: ENOENT - The requested file or directory cannot be found in the context of an Angular2 and Express.js

I have made some changes to the Angular2 app on GitHub in order to use Express.js instead of KOA. However, when I try to load the app in FireFox, I encounter the following error in the `nodemon` console: Error: ENOENT: no such file or directory The Angul ...

Creating a two-dimensional canvas within a div element using the console

I have some code that currently generates an image in the console when I hit F12. However, I would like to display this image inside a more user-friendly area such as a div on the webpage. I attempted to create a <div class = "mylog"> to place the i ...

Executing an Ajax call to a PHP form within an Express/node.JS application

Attempting to send a form using AJAX PHP within an Express application. In the AJAX file, PHP validation is triggered when the send button is clicked. Currently receiving a 404 error on the PHP file located in the public folder of Express: ../php/c ...