How do I get the sorting column text?
How do I get the sorting column text?
robertbrower
Posts: 158Questions: 1Answers: 0
To get the text of the sorting column from within my 'fnDrawCallback', I am doing this:
[code]
var xAxisLabel = $(oSettings.oInstance.dataTableSettings[0].aoColumns[oSettings.aaSorting[0][0]].nTh).attr('innerText');
[/code]
My contents of my javascript file are shown here:
[code]
$(document).ready(function () {
$('#table1').dataTable({
'bJQueryUI': true,
'sPaginationType': 'full_numbers',
'iDisplayLength': 5,
'aLengthMenu': [[5, 10, 25, -1], [5, 10, 25, 'All']],
'sScrollY': 300,
'bFilter': false,
'fnDrawCallback': function (oSettings) {
var sortColumn = oSettings.aaSorting[0][0] + 1;
if (sortColumn == 6) sortColumn = 1;
var xAxisTicks = [];
var xValues = [];
var xAxisLabel = $(oSettings.oInstance.dataTableSettings[0].aoColumns[oSettings.aaSorting[0][0]].nTh).attr('innerText');
oSettings.oInstance.find('tbody>tr').each(function () {
var tr = $(this);
var axisTick = tr.children('td:nth-child(' + sortColumn + ')').attr('innerText');
xAxisTicks.push(axisTick);
var value = parseFloat(tr.children('td:nth-child(4)').attr('innerText'));
xValues.push(value);
});
$('#chart1').html('');
$.jqplot('chart1', [xValues], {
title: 'Book Prices',
series: [{ renderer: $.jqplot.BarRenderer}],
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: { angle: -30, fontSize: '10pt' }
},
axes: {
xaxis: {
label: xAxisLabel,
renderer: $.jqplot.CategoryAxisRenderer,
ticks: xAxisTicks
}
}
});
}
});
});
[/code]
Is there an easier, faster, or better way to retrieve the innerText of the column which is being used for the sort?
Many, many thanks.
Robert
[code]
var xAxisLabel = $(oSettings.oInstance.dataTableSettings[0].aoColumns[oSettings.aaSorting[0][0]].nTh).attr('innerText');
[/code]
My contents of my javascript file are shown here:
[code]
$(document).ready(function () {
$('#table1').dataTable({
'bJQueryUI': true,
'sPaginationType': 'full_numbers',
'iDisplayLength': 5,
'aLengthMenu': [[5, 10, 25, -1], [5, 10, 25, 'All']],
'sScrollY': 300,
'bFilter': false,
'fnDrawCallback': function (oSettings) {
var sortColumn = oSettings.aaSorting[0][0] + 1;
if (sortColumn == 6) sortColumn = 1;
var xAxisTicks = [];
var xValues = [];
var xAxisLabel = $(oSettings.oInstance.dataTableSettings[0].aoColumns[oSettings.aaSorting[0][0]].nTh).attr('innerText');
oSettings.oInstance.find('tbody>tr').each(function () {
var tr = $(this);
var axisTick = tr.children('td:nth-child(' + sortColumn + ')').attr('innerText');
xAxisTicks.push(axisTick);
var value = parseFloat(tr.children('td:nth-child(4)').attr('innerText'));
xValues.push(value);
});
$('#chart1').html('');
$.jqplot('chart1', [xValues], {
title: 'Book Prices',
series: [{ renderer: $.jqplot.BarRenderer}],
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: { angle: -30, fontSize: '10pt' }
},
axes: {
xaxis: {
label: xAxisLabel,
renderer: $.jqplot.CategoryAxisRenderer,
ticks: xAxisTicks
}
}
});
}
});
});
[/code]
Is there an easier, faster, or better way to retrieve the innerText of the column which is being used for the sort?
Many, many thanks.
Robert
This discussion has been closed.
Replies
[code]
$(oSettings.oInstance.dataTableSettings[0].aoColumns[oSettings.aaSorting[0][0]].nTh).attr('innerText');
[/code]
Can become:
[code]
$(oSettings.aoColumns[oSettings.aaSorting[0][0]].nTh).attr('innerText');
[/code]
Another option would be:
[code]
$('#table1 th.sorting_asc,#table1 th.sorting_desc').attr('innerText');
[/code]
Allan