Summary and average in footer based on checkbox in row
Summary and average in footer based on checkbox in row
Misiu
Posts: 68Questions: 4Answers: 2
Let me start by showing my example: http://jsfiddle.net/Misiu/TtvKW/
As You can see I have couple of columns with checkbox in second last column.
Right now footer is based on that checkbox initial value (if checkbox is selected then I use that row in summary and average)
But I'm unable to update my footer after those checkboxes are changed.
Idea is to have report that shows lets say 10 users, but we would like to be able to select only 4 of them to count sum and average.
I was able to add change handler to all of those checkboxes, but I have problem with updating mData for specific row.
First time I click on checkbox event is fired, but I can't get is to work second time. (try checking and unchecking row, see footer changes only after first click)
Also is there a better way to update single value in row?
Right now I use something like this:
[code]
$("input.updateFooter").on('click', function () {
var rowIndex = oTable1.fnGetPosition( $(this).closest('tr')[0]);
var ok = this.checked?1:0;
oTable1.fnUpdate(ok, rowIndex, 5, true, true);
});
[/code]
I would like to update only 'use' part of my data, so it would by nice to be able to refer it by name not by column, like:
[code]
oTable1.fnUpdate(newValue, rowIndex, 'mDataName', true, true);
[/code]
This way I'll be able to change columns positions and my code will still work.
Could You please help me on those two small issues?
As You can see I have couple of columns with checkbox in second last column.
Right now footer is based on that checkbox initial value (if checkbox is selected then I use that row in summary and average)
But I'm unable to update my footer after those checkboxes are changed.
Idea is to have report that shows lets say 10 users, but we would like to be able to select only 4 of them to count sum and average.
I was able to add change handler to all of those checkboxes, but I have problem with updating mData for specific row.
First time I click on checkbox event is fired, but I can't get is to work second time. (try checking and unchecking row, see footer changes only after first click)
Also is there a better way to update single value in row?
Right now I use something like this:
[code]
$("input.updateFooter").on('click', function () {
var rowIndex = oTable1.fnGetPosition( $(this).closest('tr')[0]);
var ok = this.checked?1:0;
oTable1.fnUpdate(ok, rowIndex, 5, true, true);
});
[/code]
I would like to update only 'use' part of my data, so it would by nice to be able to refer it by name not by column, like:
[code]
oTable1.fnUpdate(newValue, rowIndex, 'mDataName', true, true);
[/code]
This way I'll be able to change columns positions and my code will still work.
Could You please help me on those two small issues?
This discussion has been closed.
Replies
[code]
$(document).on('click',"input.updateFooter", function () {
var rowIndex = oTable1.fnGetPosition( $(this).closest('tr')[0] );
var ok = this.checked?1:0;
oTable1.fnUpdate(ok, rowIndex, 5, true, true);
});
[/code]
Second part of my question is still actual - how can I update data better way?
Also any tweaks to my code are welcome :)
I've manage to update my data another way:
[code]
$(document).on('click',"input.updateFooter", function () {
var rowIndex = oTable1.fnGetPosition( $(this).closest('tr')[0] );
var ok = this.checked?1:0;
//oTable1.fnUpdate(ok, rowIndex, 5, true, true);
oTable1.fnSettings().aoData[rowIndex]._aData.use=ok;
oTable1.fnDraw();
});
[/code]
Is there a better way? :)