How to make number start from 1 when export data that have been filtering?

How to make number start from 1 when export data that have been filtering?

fitrahfitrah Posts: 2Questions: 1Answers: 0
edited January 28 in Free community support

sorry sir, i have problem, How to make number start from 1 when export data that have been filtering? or the filtering data always start from number 1, not as number when in the full table. ty sir

(https://datatables.net/forums/uploads/editor/yj/cecr3wpma5q9.png "")
(https://datatables.net/forums/uploads/editor/dc/wr9kjmbutvk6.png "")

        <script>

        $(document).ready(function() {
                var table = $('#example2').DataTable( {
                    buttons: [
                            {
                        extend: 'pdfHtml5',
                        orientation: 'landscape',
                        exportOptions: {
                            columns: [ 0, 1, 2,3,4,5,6,7,8,9 ]
                            }
                    },

                    ],
                    lengthChange: true,

                } );



                table.buttons().container()
                    .appendTo( '#example2_wrapper .col-md-6:eq(0)' );
            } );

        $(document).ready(function() {

        var minDate, maxDate;

        // Custom filtering function which will search data in column four between two values
        $.fn.dataTable.ext.search.push(
            function( settings, data, dataIndex ) {
                let min = moment($('#min').val(), 'DD-MM-YYYY', true).isValid() ?
                    moment($('#min').val(), 'DD-MM-YYYY', true).unix() :
                    null;

                 let max = moment($('#max').val(), 'DD-MM-YYYY').isValid() ?
                     moment( $('#max').val(), 'DD-MM-YYYY', true ).unix():
                     null;
                var date = moment( data[9], 'DD-MM-YYYY', true ).unix();

              console.log("min: " + min + ' ' + $('#min').val())
              console.log($('#min').val() + ": " + moment($('#min').val(), 'DD-MM-YYYY', true).isValid())
              console.log("max: " + max + ' ' + $('#min').val())

                if (
                    ( min === null && max === null ) ||
                    ( min === null && date <= max ) ||
                    ( min <= date   && max === null ) ||
                    ( min <= date   && date <= max )
                ) {
                    return true;
                }
                return false;
            }
        );

        // Create date inputs
        minDate = new DateTime($('#min'), {
                format: 'DD-MM-YYYY'
        });
            maxDate = new DateTime($('#max'), {
                format: 'DD-MM-YYYY'
            });

        // DataTables initialisation
        var table = $('#example2').DataTable();

        // Refilter the table
        $('#min, #max').on('change', function () {
                table.draw();
        });

            }); 
        </script>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    Does this example do what you want? The index is recalculated each time the table is searched or sorted.

    Kevin

  • fitrahfitrah Posts: 2Questions: 1Answers: 0

    ty... sirr

Sign In or Register to comment.