Okay
  Public Ticket #876189
Timestamp on entries
Closed

Comments

  •  2
    Robert started the conversation

    Hi-- I'd like to add a timestamp to each row when it's added. Is there some way to do this either through the admin or programmatically?

    Thanks!

  • [deleted] replied

    Hi Robert,

    We do not have functionality like that in current version of our plugin but we will have timestamp as column type in next version. You could use our built in filters to manipulate data in table:

    I wrote this little function that is doing what you need. 

    function table_edit_time ( $formdata, $table_id ) {
        if ( $table_id == 1 ) {
            $formdata['time'] = time();
        }
        return $formdata;
    }
    add_filter('wpdatatables_filter_formdata_before_save', 'table_edit_time', 10, 2);

    You could use it in function.php file from your theme. If you don't know how to do it please take a look at our video tutorial

    This function will add timestamp from php function - time() to table with id - 1 and in column with name 'time'. You need to have one empty column with type integer.

    Please change table id as well as column name to ones that you need.


  •  2
    Robert replied

    Hi Miljko,

    I used this function:

    function voca_table_edit_time( $formdata, $table_id ) {
       if ( $table_id == 2 ) {
          $formdata['updated'] = time();
       }
    
       return $formdata;
    }
    
    add_filter( 'wpdatatables_filter_formdata_before_save', 'voca_table_edit_time', 10, 2 );

    Where 2 is the ID of the table, which I got from the wp_datatables table ID field, and 'updated' is the name of the field I added, verified against the `data-key` attribute on the input. The filter does not seem to timestamp on saving from the front-end. Should I hook this in somewhere else? Thanks!

  • [deleted] replied

    Hi Robert,

    Please provide me a temporary WP-admin login for your site where this happens, so we could log in and take a look ‘from the inside’ as that’s the most efficient way to see and resolve the issue. We do not interfere with any data or anything else except for the plugin (in case that’s a production version of the site), and of course we do not provide login data to third party. 

  •   Robert replied privately
  •   [deleted] replied privately
  •   Robert replied privately
  • [deleted] replied

    Hi Robert,

    I don't see column name 'updated' in your table. You need to have column with that name and type integer.

  •  2
    Robert replied

    Hi Miljko--

    My mistake, I forgot to add it in the DB on the deployed version (it was on my local dev env). 

    The column is hidden with CSS on the front end, but you should see it in the table editor here: 
    /wp-admin/admin.php?page=wpdatatables-editor&table_id=2

    The Updated field just populates with zeroes.


    Thanks!

  • [deleted] replied

    Hi Robert,

    Your website is unreachable at this moment. Please let me know when I can take a look. 

  •  2
    Robert replied

    Very strange-- I'm in there now. http://status-1and1.com/#undefined

    The link in the previous post is only a fragment to hide my base URL in a public ticket.

  • [deleted] replied

    Hi Robert,

    The link that you send to me was from your local development and that has led to confusion. 

    The filter that I sent you is the new one and it is not included in current version of our plugin. Please accept my apologies for not mentioning that. Anyway I added it into your code and now everything is working. It's in 

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

    around line 207. 

    It will be included in next version and until then you can just copy and paste that file into your production environment.