Combining row() and column() for footerCallback
Combining row() and column() for footerCallback

I have many rows which I want to filter by content of a special column.
If column[12] contains "...gelöscht..." it's rows index ist pushed into rowIndexes.
This works. rowIndexes contains only rowIds of rows, that don't contain "mySearchString".
sumEur() still returns sum of all rows!
Please help me, I'm stuck.
var columnIndexForSum = 5;
var rowIndexes = [];
tableApi.rows().eq(0).each( function ( ix )
{
var row = tableApi.row( ix );
var data = row.data();
if(data[12] != mySearchString)
{
rowIndexes.push(ix);
}
});
value = formatCurrency(tableApi.row([1,2]).column( columnIndexForSum, {filter:'applied'} ).data().sumEUR());
jQuery.fn.dataTable.Api.register( 'sumEUR()', function ( )
{
var data = this.flatten();
data = $.grep(data, function(value)
{
return value.indexOf('EUR') > 0;
});
return data.reduce( function ( a, b )
{
if(String(a).indexOf('<') >= 0)
{
a = a.replace(/( |<([^>]+)>)/ig, '');
}
if(String(b).indexOf('<') >= 0)
{
b = b.replace(/( |<([^>]+)>)/ig, '');
}
if(String(a).indexOf(',') >= 0)
{
a = a.replace(/\./g,'');
a = a.replace(',','.');
a = a.replace('EUR','');
a = a.trim();
a = parseFloat(a);
}
if(String(b).indexOf(',') >= 0)
{
b = b.replace(/\./g,'');
b = b.replace(',','.');
b = b.replace('EUR','');
b = b.trim();
b = parseFloat(b);
}
return (((a*100) + (b*100)) / 100);
}, 0 );
});
This discussion has been closed.
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
I would look at using
cells().data()
instead ofcolumn().data()
. UsingtableApi.row([1,2])
will return 2 rows but that won't filter the rows forcolumn()
. Userows()
with arow-selector
as a function with yourdata[12] != mySearchString
comparison. Userows().indexes()
to get the indexes needed for thecells()
. Here is an example:http://live.datatables.net/lidexeve/1/edit
You should be able to chain the
sumEUR()
function.Kevin
Thank you so much!
I got it now.
I got a new problem.
Additional to the code above I want only to sum() visible rows.
If I change row 4 to the following:
tableApi.rows({filter:'applied'}, function ( idx, data, node )
I get all rows, the rows that returned false in line 6 as well.
According to the
rows()
API the parameter order is this:Looks like you need to swap the
{filter:'applied'}
and the function. If this doesn't help then please update the test case example I provided to show the problem.Kevin
Shame on me. You are totally right!
I just needed to put "{filter:'applied'}" behind the functoin, of rows().
Thank you