Can I set a filter from one page to another DataTable?

Can I set a filter from one page to another DataTable?

arie0512arie0512 Posts: 20Questions: 6Answers: 0

Hello,

I have an overview page where they can see how many sub categories one person had, for example a person Joe Doe have an overview page which has said it had 8 requests.

I want to make from this number 8 a link to another existing DataTable (query.php) and open this page which this 8 records.

The query.php looks like this:

<div class="pb-5">
    <table id="table-request" class="table-responsive stripe hover row-border compact nowrap">
      <thead>
        <tr>
          <th>Clientnumber</th>
          <th>Name</th>
          <th>Product</th>          
        </tr>
      </thead>
      <tbody>          
      </tbody>  
    </table> 
  </div>

$(document).ready(function() {

new DataTable('#table-request', {
ajax: {
    url: '/crm/ajax/request-data.php',
    type: 'POST'
},
columns: [        
    { data: 'request.clientnumber' },        
    { data: 'request.name' },
    { data: 'request.product' }
],
columnDefs: [
  { targets: [0], className: 'dt-body-left'},
  { targets: [0], render: DataTable.render.number( '.', ',', 0 ) }
],      
order: [[0, 'asc']],
pagingType: 'full_numbers',
pageLength: 25, 
language: {
  url: 'https://cdn.datatables.net/plug-ins/1.11.5/i18n/nl-NL.json'
},          
search: {
  smart: false
} 
});

If the client has clientnumber 3, how can I make a link from the overview page which opens the query.php and filter out only clientnumber 3? So only 8 records are visible?

Kind regards,

Arie

Answers

  • kthorngrenkthorngren Posts: 22,393Questions: 26Answers: 5,143

    You can use the DeepLink plugin to get the search string parameter and perform a search.

    Alternatively you can use Javascript URLSearchParams to get the query parameters and use either search or column().search() as appropriate.

    Kevin

  • arie0512arie0512 Posts: 20Questions: 6Answers: 0

    Hi Kevin,

    Tnx for pointing me the the Deeplink plugin.

    I have now an URL on the overview page, query.php?search.search=3 which loads the query.php but unfortually it loads every record, not only clientnumber 3.

    I have edit the query.php with this:

    <script src="https://cdn.datatables.net/plug-ins/2.3.7/features/deepLink/dataTables.deepLink.min.js"></script>
    
    $(document).ready(function() {
    
    $('tabel-request').DataTable( $.fn.dataTable.ext.deepLink( [
        'search.search', 'order', 'displayStart'
    ]));  
    
    new DataTable('#request', {
    ajax: {
        url: '/crm/ajax/request-data.php',
        type: 'POST'
    },
    ....
    });
    

    Any idea why I get all the records in stead of only clientnumber 3?

    And is it possible to look into a certain column for clientnumber? Because in the other columns the number 3 can also exist. I only need to look into column 0.

    Best regards,

  • allanallan Posts: 65,545Questions: 1Answers: 10,891 Site admin

    Are you able to link to the page so I can take a look at it please?

    $('tabel-request').

    Is it missing a # for an ID selector? How does it relate to the #request table? Are you displaying two tables on this results page?

    And is it possible to look into a certain column for clientnumber?

    Yes, you can perform a filter on a specific column. column().search() with the API or searchCols for initialisation.

    I'd focus on getting the search information working first.

    Allan

  • kthorngrenkthorngren Posts: 22,393Questions: 26Answers: 5,143
    edited February 4

    Any idea why I get all the records in stead of only clientnumber 3?

    It doesn't look like you are using server side processing so if you want to only return certain records for the ajax request to /crm/ajax/request-data.php then you will probably want to use ajax.data to send the search parameters to the server and the server script will need to filter the results based on the sent search parameters. The deeplink plugin won't be useful for this case.

    Kevin

Sign In or Register to comment.