Error encountered: $(...).dataTable(...).row does not exist as a function

I am currently working with a datatable and I would like to implement a feature where the selected row is removed when clicked on.

Below is the code snippet for the datatable:

$('.data-table').dataTable({
  "aaSorting": [],
  "oLanguage": {"sSearch": ""},
  "fnDrawCallback": function (oSettings) {}
});

Additionally, here is the functionality for deleting rows:

<input type="button" class="btndel btn-primary btn btn-primary" onclick="                                                                  $(this).closest('tr').addClass('selected');
if ($('.tab1').hasClass('active')) {
  var rows = $('.data-table').dataTable().row('.selected').remove().draw();
  var xSum = 0;
  var items = document.getElementsByClassName('pp');
  var itemCount = items.length;
  var total = 0;
  $('.pp').each(function () {
  var che = isNaN($(this).text());
  if (che == false) {
    xSum += parseFloat($(this).text());
  }
});
var value1 = xSum / parseInt(itemCount);
$('#avgsold').text(value1.toFixed(2));
}
if ($('.tab2').hasClass('active')) {}" value="Delete" />

However, there seems to be an error occurring:

Uncaught TypeError: $(...).dataTable(...).row is not a function

Thank you in advance for any assistance provided.

Answer №1

Here is an alternative code snippet to use:

$('.data-table').DataTable().row('.selected').remove().draw();

or

$('.data-table').dataTable().api().row('.selected').remove().draw();

After the update to version 1.10 of the DataTables plugin, newer API methods like row() can now be accessed using either DataTable() or dataTable().api(). The older API methods are still accessible through dataTable().

For more information, you can refer to the API documentation.

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

Utilizing long polling technique with jQuery/AJAX on the server end

Currently, I am facing an issue with long polling on a single page that contains multiple pages. The problem arises when a new request is made while a previous request is still processing. Even though I attempt to abort the previous request, it completes b ...

Discover the power of the "Load More" feature with Ajax Button on

After browsing through the previous questions and experimenting with various techniques, I've come close to a solution but still can't get it to work. The closest example I found is on Stack Overflow: How to implement pagination on a custom WP_Qu ...

Incorporate Thymeleaf's HTML using the powerful JavaScript framework, jQuery

I am facing an issue where the Thymeleaf rendered HTML code is not being displayed by the Browser when I try to insert it using JavaScript. $('<span [[$ th:text#{some.property.key}]] id="counter" class="UI-modern"> </ ...

Tips for dynamically filling HTML content with Ajax calls

I'm currently in the process of creating a website for my semester project, and I need to dynamically populate HTML content from an AJAX response. The data I'm receiving is related to posts from a database, but I specifically need to display 5 jo ...

Utilizing MVC6 to send both a CSV file and a string to a controller via Ajax

I'm encountering an issue that involves sending a CSV file along with the value of a string variable back to the controller. Individually, I've been successful in sending the file via the form's submit button and the string variable via aja ...

The jQuery ajax call is returning some undefined results, which is in contrast to the network response, which appears to be completely accurate

My system utilizes an oracle-db and a php-script that is triggered by a query ajax-call. Here is the php-script: $query = 'SELECT pl.event_id, pl.og2, d.name dst, pl.state, pl.note, pl.createdate FROM publevels pl LEFT JOIN dst d on (d.og2 = pl.og ...

Is there a way for me to verify that the value I retrieved from my AJAX request was successfully passed to my

The login event will be triggered by this action $('#btnLogin').click(function(){ //var data = $('#loginForm').serialize(); var email = $('#loginEmail').val(); var password = $('#lo ...

The animated loading image is taking an eternity to actually load

My website is loaded with heavy front-end features and I'm using a loading gif to help with the loading process. However, I've noticed that in Safari, there is a delay before the gif loads after the background does, which takes away from the inte ...

The power trio: jQuery, JSON, and PHP

Greetings, I'm inputting a name on a particular website and then submitting that name by clicking a button. This is the HTML Code: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; ch ...

Find the quantity of items in each list individually and add them to a new list

Seeking a solution for a seemingly simple issue. I am attempting to calculate the number of list items and then add this count to the list in the parent div. The problem lies in the fact that it always displays the value of the last item in the list. For i ...

Why is it that I am receiving just one object as a string when making an ajax call, even though the controller is supposed to be returning

I'm having trouble understanding why my $.get call is returning one single object with a string containing my elements, instead of the expected list of objects returned by my controller. Controller: public JsonResult GetInitialTags(int id) { Mod ...

Trouble with using AJAX to transfer a JavaScript variable to a PHP file

I need assistance in sending a JavaScript variable to a PHP file for displaying comments on a webpage. While I have successfully sent the JS variable to other PHP files, I'm facing issues when trying to do the same with the comment-list.php file. It ...

What are the best practices for utilizing the JQuery hasData() method effectively?

I have created a simple front-end web application where clicking a button triggers a GET Request to the Foursquare API, and then AJAX stores some of the response data into a div in the following manner: checkinsCount[i] = data.response.venues[i].stats.che ...

Tips for efficiently exporting and handling data from a customizable table

I recently discovered an editable table feature on https://codepen.io/ashblue/pen/mCtuA While the editable table works perfectly for me, I have encountered a challenge when cloning the table and exporting its data. Below is the code snippet: // JavaScr ...

The dimensions of the image are determined by its orientation

I am working with two different types of images on my website: vertical and horizontal. Currently, I have a JavaScript function that adjusts the height of all images to fit the screen size. However, I would like to modify this function so that it also adap ...

Internet Explorer is experiencing difficulties in loading content using jQuery

I'm trying to implement a method similar to the one shown in this link on the link provided below. The first link works fine in IE, but for some reason my approach is failing in IE. It's loading the content, but the old content seems to still be ...

Convert JSON response date format to a format specified by the user

The following code snippet is currently returning the dates for $("#dob") and $("#anniversery") as 2014-04-01T00:00:00 This is my current code: <script> $(function() { function log(message) { $("<div>").text(message).p ...

Tips for customizing the AjaxComplete function for individual ajax calls

I need help figuring out how to display various loading symbols depending on the ajax call on my website. Currently, I only have a default loading symbol that appears in a fixed window at the center of the screen. The issue arises because I have multiple ...

Tips for creating a highly adaptable code base- Utilize variables

Can anyone help me optimize this lengthy and cumbersome code in HTML and JS? I want to make it more efficient by using variables instead of repeating the same code over and over. In the HTML, I've used href links to switch between different months, w ...

Does the AngularJS Controller disappear when the DOM element is "deleted"?

One challenge I encountered is regarding a directive that is connected to an angularjs controller, as shown below: <my-directive id="my-unique-directive" ng-controller="MyController"></my-directive> In the controller, at a certain point, I ne ...