i want sum of column in footer

i want sum of column in footer

nitinjecnitinjec Posts: 1Questions: 1Answers: 0

```

Sno. OIC Name Case disposal statistics (Pending+Interim) cases in various court (Pending+Interim) cases case type wise
Total Disposed Interim Pending SC HC DC TC Land Related Service Matter Others
GRAND TOTAL
2 peon 1 0 0 1 0 1 0 0 0 1 0
3 dsfdfd 0 0 0 0 0 0 0 0 0 0 0
4 steno 1 0 0 1 0 0 1 0 0 0 1

<

script type="text/javascript">
$(document).ready(function() {
$('#ghatable1').dataTable({
responsive: true
});
var table = $('#ghatable1').DataTable();
var iColumns = $('#ghatable1 tfoot th').length;
//alert(iColumns);
for ( var i=2 ; i<iColumns ; i++ )
{
var column = table.column(i);
$(column.footer()).html(
column.data().reduce(function (a, b) {
return parseInt(a, 10) + parseInt(b, 10);
})
);
}
</script>```

the problem is that when I put between <td></td> tag hyperlink <a></a> the grand total in footer using above datatable java script stop working.
kindly suggest the solution when I put hyperlink between <td></td> tags

thanks in advance to all of u to support

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    You have to have a smarter method to get the values out of the inner nodes than just parseInt. You need a function that will pull the inner text out of the content.

    replace your parseInt with floatVal

    return floatVal(a) + floatval(b);
    

    This function might work for you, it does for me. If the cell contains a number, it returns that, if it's a string, it strips out $ and commas, if that fails it then pulls the inner text. You can modify it to handle your numerical situations.

    var floatVal = function (i) {
        if (typeof i === "number") {
            return i;
        } else if (typeof i === "string") {
            i = i.replace("$", "")
            i = i.replace(",", "")
            var result = parseFloat(i);
            if (isNaN(result)) {
                try {
                    var result = $(i).text();
                    result = parseFloat(result);
                    if (isNaN(result)) { result = 0 };
                    return result * 1;
                } catch (error) {
                    return 0;
                }
            } else {
                return result * 1;
            }
        } else {
            alert("Unhandled type for totals [" + (typeof i) + "]");
            return 0
        }
    };
    
This discussion has been closed.