How should i have dropdown , file exporters and sum in all for one datatable.

How should i have dropdown , file exporters and sum in all for one datatable.

nareshkumarcsgnareshkumarcsg Posts: 2Questions: 1Answers: 0
        $(document).ready(function () {


            $('#<%=GridView1.ClientID%>').DataTable({
                 "footerCallback": function (row, data, start, end, display) {
                  var api = this.api();
                // Remove the formatting to get integer data for summation
                        var intVal = function (i) {
                            return typeof i === 'string' ?
                                i.replace(/[\$,]/g, '') * 1 :
                                typeof i === 'number' ?
                                    i : 0;
                        };

                            // Total over all pages
                            total6 = api
                                .column(6)
                                .data()
                                .reduce(function (c, d) {
                                    return intVal(c) + intVal(d);
                                }, 0);

                    pageTotal6 = api
                        .column(6, { page: 'current' })
                        .data()
                        .reduce(function (c, d) {
                            return intVal(c) + intVal(d);
                        }, 0);


                    $(api.column(6).footer()).html(
                        'Current/Total  : ' + pageTotal6 + '/' + total6
                    );


                            total = api
                            .column(7)
                            .data()
                            .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                            }, 0);


                            // Total over this page
                            pageTotal = api
                                .column(7, { page: 'current' })
                                .data()
                                .reduce(function (a, b) {
                                    return intVal(a) + intVal(b);
                                }, 0);

                            // Update footer
                            $(api.column(7).footer()).html(
                                'Current/Total  : ' + pageTotal + '/' + total 
                            );
                }








            });




        });

        $(document).ready(function () {
            $('#<%=GridView1.ClientID%>').DataTable({

                dom: 'Bfrtip',
                buttons: [
                    'copy', 'csv', 'excel', 'pdf', 'print'
                ]

            });
        });

Answers

  • nareshkumarcsgnareshkumarcsg Posts: 2Questions: 1Answers: 0

    also this has to be added for dropdowns

    $('#<%=GridView1.ClientID%>').DataTable({

                initComplete: function () {
    
    
    
                    this.api().columns().every(function () {
    
    
    
    
                        var column = this;
                        var select = $('<select><option value=""></option></select>')
                            .appendTo($(column.header()))
    
                            .on('change', function () {
                                var val = $.fn.dataTable.util.escapeRegex(
                                    $(this).val()
                                );
    
                                column
                                    .search(val ? '^' + val + '$' : '', true, false)
                                    .draw();
                            });
    
                        column.order('asc').draw(false).data().unique().each(function (d, j) {
                            select.append('<option value="' + d + '">' + d + '</option>')
                        });
                    });
                }
    
    
            });
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited February 2022

    You need to combine the elements into the one initialisation object, so something like:

    $('#<%=GridView1.ClientID%>').DataTable({
        dom: 'Bfrtip',
        buttons: [
                'copy', 'csv', 'excel', 'pdf', 'print'
        ],
        initComplete: function () {
           ...
        },
        "footerCallback": function (row, data, start, end, display) {
            ...
         }
    });
    

    Colin

Sign In or Register to comment.