number of element

number of element

marcpiratmarcpirat Posts: 51Questions: 18Answers: 0

hi

I use a datatable to search data

                  var searchSamplingsResultsTable = $("#searchSamplingsResultsTable").DataTable({
                        language: {
                            "url" :  urlI18n
                        },
                        'bLengthChange': false, //hide 'show entries dropdown
                        'processing': true,
                        'serverSide': true,
                        'pagingType': 'simple_numbers',
                        'dom': 'tp',
                        'ajax': {
                            'type': 'get',
                            'url': url,
                            'data': function (d) {
                                var current = $('#searchSamplingsResultsTable').DataTable();
                                d.page = (current != undefined) ? current.page.info().page : 0;
                                d.size = (current != undefined) ? current.page.info().length : 5;
                                d.sort = d.columns[d.order[0].column].data + ',' + d.order[0].dir;

                                d.id=$("#searchSamplesForm input[name=id]").val(); 

                                if($("#searchSamplesBuildDatePicker").val()!=""){
                                    d.buildDate=$("#searchSamplesBuildDatePicker").data('daterangepicker').startDate.format('YYYY-MM-DD');
                                }

                                d.productTypesId = $("#searchSamplesForm select[name=productTypesId]").val();
                                d.productsId = $("#searchSamplesForm select[name=productsId]").val();

                                d.dimensionsId = $("#searchSamplesForm select[name=dimensionsId]").val();
                                d.colorsId = $("#searchSamplesForm select[name=colorsId]").val();

                                d.factoriesId = $("#searchSamplesForm select[name=factoriesId]").val();
                                d.machinesId = $("#searchSamplesForm select[name=machinesId]").val();

                                d.suppliersId = $("#searchSamplesForm select[name=suppliersId]").val();

                                if($("#searchSamplesBuildStartDatePicker").val()!=""){
                                    d.buildStartDate=$("#searchSamplesBuildStartDatePicker").data('daterangepicker').startDate.format('YYYY-MM-DD');
                                }

                                if($("#searchSamplesBuildEndDatePicker").val()!=""){ 
                                    d.buildEndDate=$("#searchSamplesBuildEndDatePicker").data('daterangepicker').startDate.format('YYYY-MM-DD');
                                }

                                d.passing = $("#passing").prop('checked');
                                d.retained = $("#retained").prop('checked');
                            }
                        },
                        'columns': [
                            {'data': 'id'}, 
                            {'data': 'buildDate'},
                            {'data': 'productTypeName'},
                            {'data': 'productName'},
                            {'data': 'factories'},
                            {'data': 'machineName'},
                            {'data': 'dimensions'},
                            {'data': 'colors'}
                        ]
                    });

When I click search, I display data

           $("#searchSamplings").on('click', function (e) {

                e.preventDefault();

                searchSamplingsResultsTable.draw();

               //how many number?

            });

How to get the number of data who are displayed on the click event?

thanks

Answers

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765
    edited September 2018

    You can use the count() api. There is an example in the doc that is close to what you want. In stead of this (from the doc) table.rows( '.selected' ).count() you would use a selector-modifier to filter the row count. Something like this should work:

    `table.rows( {search:'applied'} ).count()
    

    Kevin

This discussion has been closed.