Code Monkey home page Code Monkey logo

Comments (3)

Holt59 avatar Holt59 commented on August 19, 2024

I tomfumb, I'm sorry to only answer you now but I've been away for a while. I am sorry but I will not be able to fix the issue you are facing, simply because it would require a lot of modification for something quite unusual. You should not use HTML elements to store metadata about your rows: You could use the data attribute of your th elements to store such information, or even better use the datatable plugin to internally store these informations and only display what you want.

from datatable.

tomfumb avatar tomfumb commented on August 19, 2024

I agree that the data attribute can be useful but in my scenario this was not possible. A server-side script was generating the HTML through a repeating row template and hidden table columns was the only way I had to communicate metadata.

Regardless of the reason I think it's sensible for javascript libraries to respect DOM display properties, or at least provide that as a non-default option, to adhere to the 'principle of least astonishment'. Thanks for your hard work providing Open Source tools to strangers!

from datatable.

Holt59 avatar Holt59 commented on August 19, 2024

Even if I think this is not useful anymore for you, I will put some useful stuff here (and close this issue).

After some tries, I didn't manage to easily solve this issue. Because of the ways filtering and sorting work, it would require a lot of works to ยซ respect ยป hidden columns.

However, there is a very simple way to deal with hidden columns, but which required a few steps from you (or anyone using the plugins). Assuming you have 3 columns, and the second one is hidden, you could do the following (the important options are sort, filters and lineFormat):

$('#mydatatable').datatable({
    sort: {
        0: true,
        2: true
    },
    filters: {
        0: true,
        2: 'select'
    },
    lineFormat: function (id, data) {
        var tr = $('<tr></tr>') ;
        tr.append('<td>' + data[0] + '</td>') ;
        tr.append('<td style="display: none">' +
        tr.append('<td>' + data[2] + '</td>') ;
        return tr ;
    }
}) ;

The key here is to:

  • Use objects instead of arrays from sort and filters options, so you can specify only the columns you want (0 and 2 here).
  • Use a custom lineFormat to display hidden columns.

from datatable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.