No matching results found data table after performing 2nd ajax from each.(function(){ $(this).click

No matching results found data table after performing 2nd ajax from each.(function(){ $(this).click

Lesley1122Lesley1122 Posts: 1Questions: 0Answers: 0
edited July 2019 in Free community support

Hi im having some trouble here.

When I click the Top 50 it gives me the correct result but when I click the Top 50-100 the result is "No Matching Results Foung"
Somebody help me with this. here's my code

 <div class="d-flex">
                                              <ul class="list-inline mx-auto justify-content-center">
                                                <li class="list-inline-item clientSorting" value="0"><i class="fa fa-square"style="color:#6AB187"></i> All</li>
                                                <li class="list-inline-item clientSorting" value="50"><i class="fa fa-square"style="color:#6AB187"></i> Top 50</li>
                                                <li class="list-inline-item clientSorting" value="100"><i class="fa fa-square"style="color:#1C4E80"></i> Top 51-100</li>
                                                <li class="list-inline-item clientSorting" value="150"><i class="fa fa-square"style="color:#DBAE58"></i> Top 101-150</li>
                                                <li class="list-inline-item clientSorting" value="151"><i class="fa fa-square"style="color:#F1F1F1;"></i> 151 - Nth</li>
                                              </ul>
                                            </div>
                                            <center>
                                                 <table id="clientdatatable" class="table table-bordered">
                                                  <thead>
                                                    <tr>
                                                    
                                                      <th style="color:#000">Business Partner</th>
                                                      <th style="color:#000">Account Balance</th>
                                                      <th style="color:#000">Credit Limit</th>
                                                      <th style="color:#000">Price List</th>
                                                      <th style="color:#000" width="10%">Category</th>
                                                      <th style="color:#000" width="10%">Row Main</th>
                                                      <th style="color:#000">BP CODE</th>
                                                    </tr>
                                                  </thead>                    
                                                  
                                                  </table>
                                            </div>```

here's my ajax

``` $(document).ready(function() {
    var table= $('#clientdatatable').DataTable({
        "ajax": {
            url : 'url',
            type : 'GET'
        },
          retrieve: true,
          stateSave: true,
    
        "createdRow": function( row, data, dataIndex){
            if( data[5] <=50 ){
                    $(row).css("background-color","#6ab187");
                                $(row).css("color","black");
            }else if( data[5] >50 && data[5] <=100 ){
                    $(row).css("background-color","#1c4e80");
                                $(row).css("color","black");
            }else if( data[5] >100 && data[5] <=150 ){
                    $(row).css("background-color","#dbae58");
                                $(row).css("color","black");
            }else{
                    $(row).css("background-color","#F1F1F1");
                                $(row).css("color","black");
            }
        },

        "columnDefs": [
            { className: "view_history", "targets": [ 0 ] }
          ],
    

    });
    $('.clientSorting').each(function(){
        //var topSort;
        $(this).click(function(e) {
            function sortFuck(params){
            console.log(params);
             $.fn.dataTable.ext.search.push(
                function( settings, data, dataIndex ) {
                    //var min = parseInt( $('#min').val(), 50 );
                    //var max = parseInt( $('#max').val(), 50 );
                    var rowmain = parseFloat( data[5] ) || 0; // use data for the age column
                    if (params == 50){
                        //console.log(val);
                        if ( ( isNaN( 1 ) && isNaN( 50 ) ) ||
                             ( isNaN( 1 ) && rowmain <= 50 ) ||
                             ( 1 <= rowmain   && isNaN( 50 ) ) ||
                             ( 1 <= rowmain   && rowmain <= 50 ) )
                        {
                            return true;
                        }
                        return false;
                    }else if (params == 100){
                        if ( ( isNaN( 51 ) && isNaN( 100 ) ) ||
                             ( isNaN( 51 ) && rowmain <= 100 ) ||
                             ( 51 <= rowmain   && isNaN( 100 ) ) ||
                             ( 51 <= rowmain   && rowmain <= 100 ) )
                        {
                            return true;
                        }
                        return false;
                    }else if (params == 150){
                        if ( ( isNaN( 101 ) && isNaN( 150 ) ) ||
                             ( isNaN( 101 ) && rowmain <= 150 ) ||
                             ( 101 <= rowmain   && isNaN( 150 ) ) ||
                             ( 101 <= rowmain   && rowmain <= 150 ) )
                        {
                            return true;
                        }
                        return false;
                    }else if (params == 151){
                        if ( ( isNaN( 151 ) && isNaN( 1000 ) ) ||
                             ( isNaN( 151 ) && rowmain <= 1000 ) ||
                             ( 151 <= rowmain   && isNaN( 1000 ) ) ||
                             ( 151 <= rowmain   && rowmain <= 1000 ) )
                        {
                            return true;
                        }
                        return false;
                    }else{
                        if ( ( isNaN( 1 ) && isNaN( 1000 ) ) ||
                             ( isNaN( 1 ) && rowmain <= 1000 ) ||
                             ( 1 <= rowmain   && isNaN( 1000 ) ) ||
                             ( 1 <= rowmain   && rowmain <= 1000) )
                        {
                            return true;
                        }
                        return false;
                    }
                    
                }
                
            );
            
        }
            var topSort = this.value;
            
            //alert(topSort);
            if (topSort == 50){
                sortFuck(topSort);
                var table = $('#clientdatatable').DataTable();
                table.draw();
            }else {
                
                sortFuck(topSort);
                var table = $('#clientdatatable').DataTable();
                table.draw();
                alert('else');
            }
            
            
        });
        
        
    });
  }); 

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Replies

This discussion has been closed.