API #fnSortNeutral - Get Trigger if sorting?
API #fnSortNeutral - Get Trigger if sorting?
hi, how may i do this:
the user clicks onto a row and starts the sorting. i want to display a Remove Order button AFTER he sorted the table away from standard sorting. i managed to hide the span #sorted after http://datatables.net/plug-ins/api#fnSortNeutral was called. the function works fine and returns to original sorting ... but how do i trigger the initial klick by the user on any row of the table to SHOW the hidden span #sorted again? so the "remove order" span only appears when something is sorted by the user???
hopefully u understand ... :)
thanks for any help ... stefan
the user clicks onto a row and starts the sorting. i want to display a Remove Order button AFTER he sorted the table away from standard sorting. i managed to hide the span #sorted after http://datatables.net/plug-ins/api#fnSortNeutral was called. the function works fine and returns to original sorting ... but how do i trigger the initial klick by the user on any row of the table to SHOW the hidden span #sorted again? so the "remove order" span only appears when something is sorted by the user???
hopefully u understand ... :)
thanks for any help ... stefan
This discussion has been closed.
Replies
Basically you can list for the 'sort' event which is emitted from the table by DataTables ( http://datatables.net/docs/DataTables/1.9.4/#sort ). Wen that event is found you know the table is being sorted, so we can show the button. When the button is click it is hidden again (enable / disable might be another option).
Regards,
Allan
$("#FTABLEreset").click(function () {
/* Remove all filtering */
$('#<? echo $tableName; ?>').dataTable().fnFilterClear();
$("#FTABLEreset").css('display', 'none');
});
$("#FSORTreset").click(function () {
/* Remove all sorting */
$('#<? echo $tableName; ?>').dataTable().fnSortNeutral();
$("#FSORTreset").css('display', 'none');
});
/* Hide SORTbutton */
$('#<? echo $tableName; ?>').on('sort', function () {
$('#FSORTreset').css('display', 'block');
} );
/* Hide Filterbutton */
$('#<? echo $tableName; ?>').on('filter', function () {
$("#FTABLEreset").css('display', 'block');
} );
if i call .on('filter', function () it seams that on('sort', function () is also fired... this means, klicking on the "remove filters" button adds the display:block to the befor hidden "remove sort orders" button. is it possible, that on'sort' is the same call as on'filter' ??? am i wrong?
Here is a solution - rather than listening for the 'sort' event from the table, listen for the click event on the headers (which is when sorting occurs): http://live.datatables.net/agaruc/2/edit
Allan
1. is something sorted away of initial sorting? yes -> show "remove sort" button
2. is something filtered ? yes -> show "reset filter" button ...
only listening to the click events seams not to do the job... :(
maybe it's because of the complex structure of my tables as you might remember... using quick filters and so on...
i guess i'm only able to use one of these buttons.