userButtons - Add custom buttons.

Discuss MySQL Ajax Table Editor Paid Version

userButtons - Add custom buttons.

Postby mate_user » Tue May 04, 2021 8:10 pm

Purchased the paid version this week,

The 'Usage 2' from the documentation 'userButtons - Add custom buttons.' is not working for me.

1. The button does not show up unless I add
Code: Select all
'button_info' => '',


2. When clicking the button nothing fires, not even the confirm_msg.

3. This line is throwing an error
Code: Select all
'no_update' = false
had to remove that line.

Can I get an example of updated working code?

I am trying to eventually incorporate 'Export Selected' as shown in this post:

viewtopic.php?f=4&t=998&p=3961&hilit=export+checked&sid=87242fce80cefc44a6cb9cbbd832e268#

Thanks!
mate_user
 
Posts: 8
Joined: Tue May 04, 2021 8:00 pm

Re: userButtons - Add custom buttons.

Postby admin » Tue May 04, 2021 9:41 pm

There are several ways to accomplish this but this is the way I would do it:

Add the user buttons like this:

Code: Select all
      $userButtons[] = array(
           'button_html' => '<button onclick="'.$this->mateInstances[0].'.handleCustomExport();">Custom Export</button>'
      );

      $this->Editor->setConfig('userButtons',$userButtons);


Add a new javascript function in the ajax_table_editor.js file, inside the mate object like this:

Code: Select all
      handleCustomExport: function() {
         var selectedRows = this.getSelectedRows();
         var numRows = Object.size(selectedRows);
         var sessionData = this.getSessionData();

         if(numRows == 0) {
            this.showTooltipMsg(mateSelectRow);
         } else {

            var selectedRowsArray = []

            for (var key in selectedRows) {
               selectedRowsArray.push(selectedRows[key])
            }

            window.location.href = 'ProDemo.php?custom_export=1&selected_rows=' + selectedRowsArray.join(',') + '&session_data='+encodeURIComponent(sessionData);
         }
      },


And add the following code in the constructor of the config file (in this case it would be ProDemo.php)
Code: Select all
      else if(isset($_GET['custom_export']))
      {
         $this->Editor->data['sessionData'] = $_GET['session_data'];
         $this->Editor->setDefaults();
         ob_end_clean();
         header('Cache-Control: no-cache, must-revalidate');
         header('Pragma: no-cache');
         header('Content-type: application/x-msexcel');
         header('Content-Type: text/csv');
         header('Content-Disposition: attachment; filename="'.$this->Editor->tableName.'.csv"');
         // Add utf-8 signature for windows/excel
         echo chr(0xEF).chr(0xBB).chr(0xBF);

         $escapedRowIds = [];

         foreach (explode(',', $_GET['selected_rows']) as $id) {
            $escapedRowIds[] = $this->escapeData($id);
         }

         $this->Editor->sqlFilters = "id in (" . implode(',', $escapedRowIds) . ")";
         echo $this->Editor->exportInfo();
         exit();
      }


After adding that code, it should work.
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: userButtons - Add custom buttons.

Postby mate_user » Wed May 05, 2021 5:11 pm

PHP Parse error: syntax error, unexpected '['

Which is referring to
Code: Select all
$escapedRowIds = [];
in the constructor.

I commented that line out for now but then getting this error:
Code: Select all
Uncaught TypeError: m2_.handleCustomExport is not a function
even though I have the function inside the mate object in ajax_table_editor.js
mate_user
 
Posts: 8
Joined: Tue May 04, 2021 8:00 pm

Re: userButtons - Add custom buttons.

Postby admin » Wed May 05, 2021 6:45 pm

Have you done a hard refresh on the browser to reload the javascript?
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: userButtons - Add custom buttons.

Postby admin » Wed May 05, 2021 6:48 pm

Also if you are using an older version of php you cannot use the square bracket syntax for arrays.

You might have to use $escapedRowIds = array(); instead.
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: userButtons - Add custom buttons.

Postby mate_user » Thu May 06, 2021 4:11 pm

PHP Fatal error: Call to undefined method UploadToDir::escapeData() in /var/www/xxxx/xxxx/xxxx.php on line 595, referer: https://xxxx/xxxx/xxxx.php

Line 595 consists of:

Code: Select all
$escapedRowIds = $this->escapeData($id);
mate_user
 
Posts: 8
Joined: Tue May 04, 2021 8:00 pm

Re: userButtons - Add custom buttons.

Postby mate_user » Thu May 06, 2021 4:32 pm

I assume my older version of PHP also does not have escapeData() function.
mate_user
 
Posts: 8
Joined: Tue May 04, 2021 8:00 pm

Re: userButtons - Add custom buttons.

Postby mate_user » Fri May 07, 2021 4:16 pm

I moved the script to a PHP 7 server.

I am getting this error:

Code: Select all
PHP Fatal error:  Uncaught Error: Call to undefined method UploadToDir::escapeData() in /home/XXXXX/public_html/XXXXX/XXXXX.php:595
Stack trace:
#0 /home/XXXXX/public_html/XXXXX/XXXXX.php(625): UploadToDir->__construct()
#1 {main}
  thrown in /home/XXXXX/public_html/XXXXX/XXXXX.php on line 595


Line 595 consists of:

Code: Select all
   $escapedRowIds[] = $this->escapeData($id);
mate_user
 
Posts: 8
Joined: Tue May 04, 2021 8:00 pm

Re: userButtons - Add custom buttons.

Postby mate_user » Fri May 07, 2021 4:56 pm

I ended up replacing

Code: Select all
$escapedRowIds[] = $this->escapeData($id);


With

Code: Select all
$escapedRowIds[] =$mysqli_custom->real_escape_string($id);


But, I had to add a custom connection/disconnect to mysql inside the }else if{

If there's a better way please let me know.

Thank you!
mate_user
 
Posts: 8
Joined: Tue May 04, 2021 8:00 pm


Return to Paid Version

Who is online

Users browsing this forum: No registered users and 1 guest

cron