data load issue

data load issue

alord84alord84 Posts: 24Questions: 15Answers: 1
edited July 2015 in Editor
var editor; // use a global for the submit and return data rendering in the examples
http://debug.datatables.net/ecegac 


$(document).ready(function() {
    
   editor = new $.fn.dataTable.Editor( {
         ajax: "../php/gets.php",
        table: "#example",
        fields: [ {
                label: "id:",
                name: "loans.id"
            }
        ]
    } );

var table = $('#example').DataTable({
    "dom": "Tfrtip",
    "ajax": "../php/gets.php",
    "columns": [
        {
            "title": "Loan ID",
            "data": "loans.id",
            "visible": false
        }, {
            "title": "UUID",
            "data": "loans.uuid"
        }, {
            "title": "Branch",
            "data": "annualtargets.Branch",
            "sortable": false
        }, {
            "title": "Month",
            "data": "annualtargets.Month",
            "sortable": false
        }, {
            "title": "Year",
            "data": "annualtargets.Year",
            "sortable": false
        }, {
            "title": "BusinessLoanNumber",
            "data": "annualtargets.BusinessLoanNumber",
            "sortable": false
        }, {
            "title": "BusinessLoanAmount",
            "data": "annualtargets.BusinessLoanAmount",
            "sortable": false
        }, {
            "title": "RetailLoanNumber",
            "data": "annualtargets.RetailLoanNumber",
            "sortable": false
        }, {
            "title": "RetailLoanAmount",
            "data": "annualtargets.RetailLoanAmount",
            "sortable": false
        }
    ],
    
    
    "drawCallback": function (settings) {
        var api = this.api();
        var rows = api.rows({
            page: 'current'
        }).nodes();
        var last = null;
        api.column(0, {
            page: 'current'
        }).data().each(function (group, i) {
            if (last !== group) {
                $(rows).eq(i).before(
                $("<tr></tr>", {
                    "class": "group",
                    "data-id": group
                }).append($("<td></td>", {
                    "colspan": 5,
                    "class": "pocell",
                    "text": "Loan ID " + group
                })).append($("<td></td>", {
                    "id": "e" + group,
                    "class": "noCount",
                    "text": "0.00"
                })).append($("<td></td>", {
                    "id": "p" + group,
                    "class": "noCount",
                    "text": "0.00"
                })).append($("<td></td>", {
                    "id": "b" + group,
                    "class": "noCount",
                    "text": "0.00"
                })).prop('outerHTML'));
                last = group;
            }
            val = api.row(api.row($(rows).eq(i)).index()).data();
            $("#e" + val.loans.id).text(parseFloat($("#e" + val.loans.id).text()) + parseFloat(val.annualtargets.BusinessLoanAmount));
            $("#p" + val.loans.id).text(parseFloat($("#p" + val.loans.id).text()) + parseFloat(val.annualtargets.RetailLoanNumber));
            $("#b" + val.loans.id).text(parseFloat($("#b" + val.loans.id).text()) + parseFloat(val.annualtargets.RetailLoanAmount));
        });
    },
    
    
    "footerCallback": function (row, data, start, end, display) {
        var api = this.api();
        $(api.column(6).footer()).html(
            api.column(6).data().reduce(function (a, b) {
                return parseFloat(a) + parseFloat(b);
            })
        );
        $(api.column(7).footer()).html(
            api.column(7).data().reduce(function (a, b) {
                return parseFloat(a) + parseFloat(b);
            })
        );
        $(api.column(8).footer()).html(
            api.column(8).data().reduce(function (a, b) {
                return parseFloat(a) + parseFloat(b);
            })
        );
    }
    
    
});
});

This question has accepted answers - jump to:

Answers

  • alord84alord84 Posts: 24Questions: 15Answers: 1
    edited August 2015 Answer ✓

    got that solved ->

    "drawCallback": function (settings) {
        var api = this.api();
        var rows = api.rows({
            page: 'current'
        }).nodes();
        var last = null;
        api.column(0, {
            page: 'current'
        }).data().each(function (group, i) {
            group = group.split(' ').join('_')
            if (last !== group) {
                $(rows).eq(i).before(
                    $("<tr></tr>", {
                        "class": "group",
                        "data-id": group
                    }).append($("<td></td>", {
                        "colspan": 5,
                        "class": "pocell",
                        "text": "PO # " + group.split('_').join(' ')
                    })).append($("<td></td>", {
                        "id": "e" + group,
                        "class": "noCount",
                        "text": "0.00"
                    })).append($("<td></td>", {
                        "id": "p" + group,
                        "class": "noCount",
                        "text": "0.00"
                    })).append($("<td></td>", {
                        "id": "b" + group,
                        "class": "noCount",
                        "text": "0.00"
                    })).prop('outerHTML'));
                last = group;
            }
            val = api.row(api.row($(rows).eq(i)).index()).data();
            console.log(val);
            $("#e" + val.PO_Nbr.split(' ').join('_')).text(parseFloat($("#e" + val.PO_Nbr.split(' ').join('_')).text()) + parseFloat(val.Encum_Amt));
            $("#p" + val.PO_Nbr.split(' ').join('_')).text(parseFloat($("#p" + val.PO_Nbr.split(' ').join('_')).text()) + parseFloat(val.Paid));
            $("#b" + val.PO_Nbr.split(' ').join('_')).text(parseFloat($("#b" + val.PO_Nbr.split(' ').join('_')).text()) + parseFloat(val.Balance));
        });
    }
    
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Answer ✓

    I'm not sure what the question was, but good to hear you have it fixed now.

    Allan

This discussion has been closed.