≡
×
Plus
Manual
Examples
Reference
Download
Blog
Community
Support
Using links instead of dropdown for length filter
Using links instead of dropdown for length filter
Vasya
Posts: 2
Questions: 0
Answers: 0
July 2012
edited July 2012
in
General
Is there are any way to replace standard drop down with something like "10 | 25 | 50 | All" links?
Replies
Vasya
Posts: 2
Questions: 0
Answers: 0
July 2012
After looking at the donations page I realized how this can be done.
I've used
[code]
"sDom": 'f<"clear"><"table-keys-top">rtp<"clear">'
[/code]
with
[code]
$('div.table-keys-top').html('Showing 10 | 25 | 50 | all');
$("div.table-keys-top span").click( function () {
if ( this.innerHTML == "10" ) {
oTable.fnSettings()._iDisplayLength = 10;
oTable.fnDraw();
} else if ( this.innerHTML == "25" ) {
oTable.fnSettings()._iDisplayLength = 25;
oTable.fnDraw();
} else if ( this.innerHTML == "50" ) {
oTable.fnSettings()._iDisplayLength = 50;
oTable.fnDraw();
} else {
oTable.fnSettings()._iDisplayLength = -1;
oTable.fnDraw();
}
});
[/code]
allan
Posts: 65,848
Questions: 1
Answers: 10,956
Site admin
July 2012
Very nice :-).
Just one comment - it would be worth using the fnLengthChange plug-in rather than setting the "private" variables directly: http://datatables.net/plug-ins/api#fnLengthChange .
Allan
This discussion has been closed.
Replies
I've used
[code]
"sDom": 'f<"clear"><"table-keys-top">rtp<"clear">'
[/code]
with
[code]
$('div.table-keys-top').html('Showing 10 | 25 | 50 | all');
$("div.table-keys-top span").click( function () {
if ( this.innerHTML == "10" ) {
oTable.fnSettings()._iDisplayLength = 10;
oTable.fnDraw();
} else if ( this.innerHTML == "25" ) {
oTable.fnSettings()._iDisplayLength = 25;
oTable.fnDraw();
} else if ( this.innerHTML == "50" ) {
oTable.fnSettings()._iDisplayLength = 50;
oTable.fnDraw();
} else {
oTable.fnSettings()._iDisplayLength = -1;
oTable.fnDraw();
}
});
[/code]
Just one comment - it would be worth using the fnLengthChange plug-in rather than setting the "private" variables directly: http://datatables.net/plug-ins/api#fnLengthChange .
Allan