Sorting by disabled or enabled buttons

Sorting by disabled or enabled buttons

lifeislikechocolateslifeislikechocolates Posts: 2Questions: 1Answers: 0

Hello,

I'm new here, and this might be a trivial kind of question, but I'd appreciate some help. Is there a way to sort by enabled/disabled buttons from bootstrap in one column?

Here is a live tables link: http://live.datatables.net/saxepabo/1/edit?html,css,js,output

I would like to be able to sort by enabled or disabled buttons, so the content doesn't very much matter.

Answers

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    Not a trivial question - a good one :smile:. Assuming you want the ability to be able to change the state of the buttons and still have the ordering work there are two options:

    1. Use a live DOM sorting plug-in.
    2. Use a custom sorting plug-in that will read the information from the DOM elements. You would need to invalidate the row (row().invalidate()) when the button's state is updated so it can reread the information from the DOM.

    Allan

  • lifeislikechocolateslifeislikechocolates Posts: 2Questions: 1Answers: 0
    edited September 2016

    Am sorry, very weak in javascript ):

    I tried to use the second option with the following code:


    $.fn.dataTable.ext.type.order['file-size-pre'] = function ( data ) { var multiplier = 1; var str = a.className; if ( $(str).hasClass('btn btn-info btn-lg disabled') ) { multiplier = 1000; } else { multiplier = 1000000000; } return parseFloat( data ) * multiplier; };

    But I am not sure where to put in the row().invalidate() either.

    But I don't know if it'll be needed as the button will only be disabled or enabled by taking the word off the class i.e. btn btn-info btn-lg vs btn btn-info btn-lg disabled.

    Live Datables link: http://live.datatables.net/saxepabo/3/edit?html,css,output

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    $(str).hasClass('btn btn-info btn-lg disabled') isn't going to work. You can't use jQuery on a string - it needs to be a node.

    You also don't appear to actually use the file-size plug-in at all. There is no type detection for it, so you'd need to use columns.type.

    Allan

This discussion has been closed.