Okay
  Public Ticket #1702641
Permanent urls for wpDataTables applied filters
Closed

Comments

  •  5
    James Morley started the conversation

    Hi, I am looking to purchase wpDataTables as it looks an incredibly powerful tool.  I was wondering though, is it possible to have permanent urls (eirther through url parameters or perhaps just using a hash) for a 'view' of a table with filters applied?  For example http://sandbox.wpdatatables.com/large-table-demo/?Name=Butler&Product=Product%205 would load the table with the filters preset and hence the view just displaying the two matching rows?

    A second question, though lower priority - has any consideration been given to having a location data type and filtering and charts based on this?  Whilst not trivial, it would be a very powerful addition I think

  •  5
    James Morley replied

    Apologies, I can now see from https://wpdatatables.com/documentation/table-features/advanced-filtering/#filter-in-url that such filters are possible. But is there any way to have the url update when a new filter is applied?

    I also see from previous forum discussions that there have been other requests for location charts but are there any firm plans to implement it?


    Thanks

  • [deleted] replied

    Hi James,
    Thank you for your inquire.

    Glad to hear that you found filter in url option. Unfortunately our filters doesn't alter the url upon apply. Location based data and charts are previously requested and we added it to our idea list but we didn't start planning the implementation. 

  •  5
    James Morley replied

    Sorry to reopen an old ticket, but I have now bought the plugin and had a chance to test this.

    Do you know why http://www.catchingtherain.com/wpdatatables-merged-column-test/?wdt_column_filter[0]=55689 returns zero results?  It fills in the Filter input box, and if I go to that and edit it (for example remove the last digit then type it in again) it works fine and retrieves the record.

  • [deleted] replied

    Hi James,

    This was a small bug on our side which only affected columns with id 0 so it hard to find when testing.

    To solve this please find 

    wp-content/plugins/wpdatatables/controllers/wdt_ajax_actions.php:101

    and change 

    if ($column->pos == $fltColKey || $column->orig_header == $fltColKey){
    

    to

    if (intval($column->pos) === $fltColKey || $column->orig_header === $fltColKey){


  •  5
    James Morley replied

    Hi Miljko

    Done, and confirmed working. Thanks for the fix.

    Best, James

  •  5
    James Morley replied

    FYI, this bit of custom js will update the browser url (without triggering a reload) to reflect what values have been entered in filters, thereby generating a direct link to the current 'view'. Note this only works for separate filter forms, but should only need a couple of tweaks to do a version for the simple in-table filter boxes ...

    jQuery(window).load(function(){
      wpDataTables.table_1.addOnDrawCallback(function(){
        var params={};
        jQuery('.wpDataTableFilterSection').each(function(i, obj) {
          if ( inputbox = obj.id.match("table_1_(.+)_filter_sections") ) {
            if (jQuery(obj).find('input').val()) {
              var key='wdt_column_filter['+inputbox[1]+']';
              params[key] = jQuery(obj).find('input').val();
            }
          }
        }); 
        history.pushState('','','?'+jQuery.param(params));
      });
    });

    See it in action at e.g. http://www.catchingtherain.com/wpdatatables-merged-column-test/?wdt_column_filter%5B1%5D=Socotra&wdt_column_filter%5B7%5D=APIACEAE

  • [deleted] replied

    Hi James,

    Thank you for sharing this. It is really interesting solution. Could we use it in this or modified state to share it with other customers?

  •  5
    James Morley replied

    Of course. I'm not a trained programmer so I am sure your guys can make improvements, firstly to make sure it is robust and tested properly, and secondly to extend it to work with both styles of form. Glad it's of help!