Table displaying data with a filter feature that excludes specific items based on their class

I have multiple HTML tables on my website, so I created a class called datatable to meet my generic table needs. For exports like PDF and Excel, I successfully excluded columns with the ignore class.

Now, I need to dynamically exclude columns with the ignore class while filtering. I want to easily set more columns with the ignore class to prevent them from being included in the filter. It's important to note that there won't always be buttons or anchor elements (button or a), so please avoid suggesting that I simply exclude these.

For example, if there is a row with the name Edit Valvasor, I want the filter to locate the row when typing "Edit" and disregard columns with Edit buttons.

An example of this can be seen here: http://jsfiddle.net/t1h9ugqa/

Javascript:

$(document).ready(function() {
  $('.datatable').DataTable({
    lengthMenu: [
      [15, 25, 50, -1],
      [15, 25, 50, "All"]
    ],
    pageLength: 25,
    dom: '<"html5buttons"B>lTfgitp',
    aaSorting: [],
    buttons: [{
        extend: 'copy',
        exportOptions: {
          columns: ':not(.ignore)',
        }
      },
      {
        extend: 'csv',
        exportOptions: {
          columns: ':not(.ignore)',
        }
      },
      {
        extend: 'excel',
        exportOptions: {
          columns: ':not(.ignore)',
        }
      },
      {
        extend: 'pdf',
        exportOptions: {
          columns: ':not(.ignore)',
        }
      },
      {
        extend: 'print',
        customize: function(win) {
          $(win.document.body).addClass('white-bg');
          $(win.document.body).css('font-size', '10px');

          $(win.document.body).find('table')
            .addClass('compact')
            .css('font-size', 'inherit');
        }
      }
    ]
  });
});

HTML:

<table class="datatable">
  <thead>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Sum</th>
      <th class="ignore"></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>Edit Valvasor</td>
      <td>1034</td>
      <td>
        <a class="btn btn-primary" href="#">Edit</a>
      </td>
    </tr>
    <tr>
      <td>2</td>
      <td>Samuel Grixis</td>
      <td>655</td>
      <td>
        <a class="btn btn-primary" href="#">Edit</a>
      </td>
    </tr>
    <tr>
      <td>3</td>
      <td>Martin Kempinsky</td>
      <td>153</td>
      <td>
        <a class="btn btn-primary" href="#">Edit</a>
      </td>
    </tr>
  </tbody>
</table>

Answer №1

If you want to include the following code snippet:

  columnDefs: [
        { searchable: false, targets: 3 }
    ],

The code displayed in this example is as follows: //target represents the specific column number

  $('.datatable').DataTable({
lengthMenu: [
  [15, 25, 50, -1],
  [15, 25, 50, "All"]
],columnDefs: [
        { searchable: false, targets: 3 }
    ],
pageLength: 25,
dom: '<"html5buttons"B>lTfgitp',
aaSorting: [],
buttons: [{
    extend: 'copy',
    exportOptions: {
      columns: ':not(.ignore)',
    }

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

Discovering the version of the Javascript library utilized on a website - a step-by-step guide

My quest is to uncover the versions of JavaScript libraries being utilized by popular websites. By using phantomjs.exe, I successfully identified the version information for jquery. However, I am currently at a loss on how to expand this capability to inc ...

ASP.NET sending an AJAX request

Hi, I am new to the world of ajax requests and asp.net. I am facing an issue while sending an ajax request to an aspx page. Even though the server side debugging seems fine, I am encountering an error message in the response. I have already tried changing ...

The function is failing to return a false value

I have encountered a problem with my code - it works fine in Chrome but not in IE or Firefox. I've tried using return false; and event.preventDefault() but they don't seem to be effective in Firefox. The issue arises when the button grabs informa ...

Creation of a Joomla module

I'm currently working on a simple module using jQuery, however I am facing issues with disabling MooTools. In my attempt to resolve this, I utilized the following code in the default.php file: $user =& JFactory::getUser(); if ($user->get( ...

Breaking content into two sections using Javascript or jQuery

Uncertain if Javascript can handle this task, any assistance or advice is appreciated. Consider this scenario: Suppose I have a 6-paragraph long content (text only) being pulled dynamically from the database all at once. This means that all 6 paragraphs a ...

Efficient jQuery autocomplete feature for multiple text fields with unique settings

Is there a way to implement this autocomplete feature for multiple textbox elements? I am struggling with the need to dynamically change the element binding and data source based on which textbox is triggering the function. $("#element").autocomplete({ ...

What are the outcomes when invoking jQuery.post() with a blank URL parameter?

Is it true that when I submit a form with an empty action field, it will automatically submit to the current page? How does this behavior change when using ajax requests? ...

Determining the Missing Focus: Discovering the Vacant '":focus'" in Jquery

I am currently working on jQuery and facing an issue with input fields that have assigned ID's and attached .blur() events. I am struggling to identify the specific item that has gained focus: $("#"+field).blur(function() { console.log ($(this).attr ...

Tips for implementing a boundary on a multipart/form-data request when utilizing the jquery ajax FormData() function for handling several files

I'm facing an issue with my HTML form that needs to upload 3 parts to an existing REST API in a single request. The problem lies in setting a boundary on a FormData submission and I haven't been able to find relevant documentation for it. I&apos ...

Rendering nested rows in Angular datatables

How can nested tables be better displayed in angular-datatables? One solution involves using rowCallback and setting up click events: $scope.dtOptions = DTOptionsBuilder.fromSource('data.json') .withOption('rowCallback', rowCallbac ...

Implementing Object Value Assignment to an Element Using jQuery

I recently received a set of data via an API request: https://i.stack.imgur.com/YGe2D.jpg In order to display this data as selectable options, I included the following code snippet in my AJAX script: $.each($(value.routes), function(index, route){ $ ...

Determining when a message has been ignored using php

One of the features I am working on for my app is adding announcements, which are essentially personalized messages to users. Once a user receives a message and dismisses it, I want to ensure that specific message does not appear again. Here is the PHP co ...

How can I use jQuery to reposition an inner element to the front?

Imagine you have a collection of elements: <ul id="ImportantNumbers"> <li id="one"></li> <li id="two"></li> <li id="topNumber"></li> <li id="four"></li> </ul> Every five seconds, the ...

Refresh Layers in Openlayers with LayerRedraw(), Rotate Features, and Manipulate Linestring Coordinates

TLDR: I am facing difficulties with my OpenLayers map. Specifically, I want to remove and add a layer called 'track', or find a way to plot a triangle based on one set of coordinates and a heading (see below). In my OpenLayers map, there is an i ...

Utilizing the power of $.ajax() to parse through an XML document

I have a query about working with a large XML file containing 1000 nodes. Here is the code snippet I am using: $.ajax({ type: "GET", cache: false, url: "someFile.xml", ...

Navigating to a particular div using a click event

I am trying to achieve a scrolling effect on my webpage by clicking a button that will target a specific div with the class "second". Currently, I have implemented this functionality using jQuery but I am curious about how to accomplish the same task using ...

Using Javascript to Treat an HTML Document as a String

Check out the complete project on GitHub: https://github.com/sosophia10/TimeCapsule (refer to js/experience.js) I'm utilizing JQuery to develop "applications" for my website. I'm encountering a problem where I can't locate the correct synta ...

I am unable to display the content even after setting `display: block` using the `.show()`

Hello there, I have attached my javascript and html code. While in debug mode, I can see that the CSS property 'display: none' changes to 'display: block', but for some reason, the popupEventForm does not open up. Any suggestions on why ...

Error: Encountered an unexpected token while trying to parse multiple form functions

I recently added the following submission function to my .js file: $( "form" ).on( "submit", function( event ) { event.preventDefault(); var data = $( this ).serialize(); $.ajax({ type: "POST", url: "content/rev/a_sub ...

Guide on transforming Div content to json format with the use of jquery

I am trying to figure out how to call the div id "con" when the export button is clicked in my HTML code. I want it to display JSON data in the console. If anyone has any suggestions or solutions, please help! <html> <div id ="con"> < ...