Filtering and orderable false

Filtering and orderable false

miltontmiltont Posts: 18Questions: 6Answers: 0

I have the following script:

<script>
       $(document).ready( function () {
       var table = $('#myTable').dataTable( {  
       "order":[[1,"desc"],[2,"desc"],[3,"desc"],[4,"desc"],[5,"desc"]],
       "dom": '<lif<t>p>',                                                 
       lengthMenu: [[100,10,25,50,-1],[100,10,25,50,"All"]],               
       fixedHeader: {headerOffset: 80},
                           
       columnDefs: [                                                       
                   { targets: [1,2,3,7,8], className: 'dt-body-center'},
                   { targets: [4,5,6,9], className: 'dt-body-right'},
                   { targets: [1], render: DataTable.render.number( ',', '.' )},
                   { targets: [7], render: DataTable.render.number( ',', '.', 0, '$' )}
                   ]
                        
                }); 
           } );
  </script>

And I don't know how to include the following code inside this...

var table = $('#example').DataTable();
 
var filteredData = table
    .column( 0 )
    .data()
    .filter( function ( value, index ) {
        return value > 20 ? true : false;
    } );

also I tried adding the following to disallow ordering and this would not work.

{ targets: [ 0, 1, 2, 3, 4, 5 ], orderable: false },

Any assistance would be appreciated.

Milton.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 15,811Questions: 25Answers: 3,749

    also I tried adding the following to disallow ordering and this would not work.
    { targets: [ 0, 1, 2, 3, 4, 5 ], orderable: false },

    That option works here:
    http://live.datatables.net/texagicu/1/edit

    And I don't know how to include the following code inside this...

    What are you wanting to do with the code you posted?

    Please provide a test case showing the issues with details of how to replicate the problems.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • miltontmiltont Posts: 18Questions: 6Answers: 0

    Thanks Kevin, I added the orderable false but it didn't work and then I realized I missed a comma....This now works.

    With the filter Data, I don't know where to place that code inside that same script.

    I wish to filter the number of rows so that in column 3 if the value is greater than or equal to 9.

    I attempted to provide a test case, but could not get that to work.

    Milton.

  • kthorngrenkthorngren Posts: 15,811Questions: 25Answers: 3,749
    edited January 26 Answer ✓

    The filter() is used to get a data set, matching the filter rule, that can be used in Javascript, ie, the filteredData variable will contain the results. It doesn't hide / show rows in the table.

    If you are trying to filter the table display then you will need a range search, like this example.

    Are you wanting to filter the table or get a Javascript variable with filtered data?

    Kevin

  • miltontmiltont Posts: 18Questions: 6Answers: 0

    Thanks Kevin,
    That's exactly what I required.

    I had to tweak the columnDefs targets as I was getting a parameter error, but once I worked out that I was referencing too many columns I got it to work.

    Really appreciate your help.

    Milton.

Sign In or Register to comment.