Find the total number of records in fnClick: (datatables.net)

I am struggling with some code where I need to retrieve the total number of records. I posted about it on the datatables.net forum but unfortunately, no one was able to help me...

   tableTools: {
     "sSwfPath": window.STATIC_BASE + "scripts/datatable/swf/copy_csv_xls_pdf.swf",
      "aButtons": [ "pdf", "csv",
      "print",
      {   "sExtends": "text",
          "sButtonText": "TotalRecords",
          "fnClick": function () {
           var record_count = this.fnSettings().fnRecordsTotal();
           alert(record_count);
           }
      }
      ]
    }

When I try to display an alert with a simple string (e.g. "hello world"), it works fine. The issue seems to be related to retrieving the total records...

Any assistance would be greatly appreciated. Thank you.

Answer №1

I believe the issue lies in your scope: this.

Consider trying:

var table = $("#myTable").dataTable({

//...

tableTools: {
     "sSwfPath": "window.STATIC_BASE + cripts/datatable/swf/copy_csv_xls_pdf.swf",
      "aButtons": [ "pdf", "csv",
      "print",
      {   "sExtends": "text",
          "sButtonText": "TotalRecords",
          "fnClick": function () {
           var record_count = table.fnSettings().fnRecordsTotal();
           alert(record_count);
           }
      }
      ]
    }

//...

});

UPDATE: Following your response, could you attempt :

var table = $(self.table).dataTable();
instead of var table = self.table;

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

Guidelines for invoking a JavaScript function within an AngularJS controller

I have included a code snippet below. sample.js (function() { /*global angular */ 'use strict'; angular.module('myapp', ['spinner']) .controller('myCtrl', ['$scope', '$window ...

Utilizing Vue.js to ensure that nested components remain within the parent component even when the store

I have been working on a chat messaging system, where I initially populate the store with root messages and then map the state of that list (array). Everything works fine when posting a new message - the store updates and displays the new post. However, I ...

Why is my JavaScript if statement not functioning properly when paired with an else statement

Currently, I am in the process of developing a game and have encountered an issue with implementing a new item for purchase. Despite having all the necessary components in place, the code seems to be skipping over the function unexpectedly. function buy ...

Exploring the mern.io scaffolder tool - Unraveling the essence of the .need method

While exploring the code of the scaffolder mern.io, I came across an intriguing method called ".need". It appeared to be related to es6 classes, but unfortunately, I couldn't find any valuable information about it. Thus, I'm curious to know: what ...

Using a custom filter in AngularJS allows for seamless data filtering directly from the initial dataset

My goal is to implement a custom filter that will allow me to filter data based on a search word. The scope attribute gets populated in the controller's scope as shown below: naApp.controller('naCareNewTicketCtrl', ['$scope', &apo ...

Having difficulty accessing POST data through $.ajax request

I am currently working on a simple JavaScript code that is set up to send POST requests to my local server. The JavaScript and PHP files are both located on localhost, so I don't have to worry about any cross-site issues for now. Here is the JavaScrip ...

What is the best way to add a new row to an existing CSV file using json2csv in Node.js?

I need to append a new row to an existing CSV file. If the CSV file already exists, I want to add the new row after the last existing row without adding a column header. Here is the code snippet that I have been using: var fields = ['total', &a ...

What is the best way to create a CSS class for a list element in React?

I am facing an issue with styling buttons in my UI. These buttons represent different domains and are dynamically generated based on data fetched from the server using the componentDidMount() method. Since I do not know the quantity of buttons at the time ...

Reorganize a list based on another list without generating a new list

Among the elements in my HTML list, there are items with text, input fields, and tables. I also have a specific order list like [3,1,2,0]. Is it feasible to rearrange the items in the HTML list on the page based on this order list without generating a new ...

How to retrieve the row index from a table using JavaScript

This question has cropped up numerous times, and despite trying various solutions suggested before, none of them seem to be effective in my case. Within a modal, I have a table where users can make changes that are then used to update the database. The ta ...

Please request user input in order to generate a multiplication chart

Is there a way to ensure that the program works properly so that when the user inputs a value, it is included in the multiplication table? <html> <head> <title> Multiplication Table </title> <style> body{ font-family: aria ...

Using jQuery, implement a functionality where a line break is added when the Enter key is pressed. Furthermore, the added

I have a text box where users can add cars to a list. Each car is entered on a new line, and when the user presses enter, jQuery adds a \n to move to the next line. However, when I collect this string, the \n characters are "hidden" and cannot b ...

Enhancing Web Forms with PHP and AJAX Javascript

Currently, I'm working on implementing a "stream" feature that allows users to input their status. So far, I have successfully set it up, but my goal is to enable users to see their new status without having to refresh the page. I understand that uti ...

The FindProxyForURL function in a pac (proxy-auto-config) file is not compatible with the IE browser

After struggling for three days, we are still unable to solve a peculiar technical issue and now seek your assistance. The PAC (Proxy Auto-Config) file we have created works flawlessly in all browsers except for Internet Explorer (IE). The URL in questio ...

What is the best way to immediately update the state in a React functional component?

Having recently started learning React, I find myself struggling to understand the lifecycle of a functional component. Let's consider a scenario where I have multiple checkboxes labeled as: checkbox, a, b, c, and d, each corresponding to values a, b, ...

Issues with Rails not successfully sending AJAX data to the controller

I am new to AJAX, so please bear with me while I try to figure this out. My goal is to send data from a chat message box to two places – the chat box itself and to a method in my Rails backend. This way, I can display the message in real-time and also st ...

What is the best way to use jQuery to fill a dropdown menu with options from a JSON object?

Looking to populate a dropdown box #dropdown with values from a json object stored in a JavaScript string variable. How can I access each element as value/label pairs and insert them into the dropdown? The structure of the json string is as follows: [{"n ...

Is it necessary to have the script tag as the first tag in the body of the HTML?

I have a script file that needs to be included by third party implementors on their web pages. It is crucial for this script to be the first tag within the body element, like so: <body> <script type="text/javascript" src="/my_script.js"></ ...

Transform the HTML content into a JSON format file

I'm currently developing an online marketplace and trying to convert all product information like name, price, and description into json format. I have a sample code featuring a selection of products displayed in rows. <div class='cakes'& ...

Nextjs: Issues with Dropdown functionality when using group and group-focus with TailwindCSS

My goal is to make an array visible once a button is clicked. By default, the array should be invisible, similar to drop-down menus in menu bars. I am utilizing the group and group-focus classes. While the array disappears as expected, it does not reappear ...