HELP! Selecting individual rows to export to CSV

Discuss MySQL Ajax Table Editor

HELP! Selecting individual rows to export to CSV

Postby cody » Wed Mar 07, 2012 4:50 pm

Hi I was wondering how to select individual rows to export to CSV. Right now when I click the export button, I get all the rows in my database. I was wondering if a basic user could select individual rows to export. Any help is appreciated. Thanks for your time.
cody
 
Posts: 2
Joined: Wed Mar 07, 2012 4:44 pm

Re: HELP! Selecting individual rows to export to CSV

Postby admin » Sat Mar 17, 2012 4:10 pm

You could create a user button to do this.
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: HELP! Selecting individual rows to export to CSV

Postby cody » Thu Mar 22, 2012 12:08 am

Hi OK here is what I have... Not sure how to code the html hash attribute to export the individual rows. I declared the 'M' permission and added the button config. Could you please tell me which file to edit and if it is quick and easy the html hash attribute to export the individual checked rows? Thank you so much for your help. Here is my code below:

$tableName = 'employees';
$primaryCol = 'id';
$errorFun = array(&$this,'logError');
$permissions = 'TQSXM';
$userButtons[] = array('label' => 'Export Individual Checked Rows', 'button_info' => 'hash of html attributes that will be placed in the button tag');

$this->Editor = new AjaxTableEditor($tableName,$primaryCol,$errorFun,$permissions,$tableColumns);
$this->Editor->setConfig('tableInfo','cellpadding="1" width="1000" class="mateTable"');
$this->Editor->setConfig('orderByColumn','first_name');
$this->Editor->setConfig('addRowTitle','Add Employee');
$this->Editor->setConfig('editRowTitle','Edit Employee');
$this->Editor->setConfig('userButtons',$userButtons);
//$this->Editor->setConfig('iconTitle','Edit Employee');
}
cody
 
Posts: 2
Joined: Wed Mar 07, 2012 4:44 pm

Re: HELP! Selecting individual rows to export to CSV

Postby admin » Mon Mar 26, 2012 3:23 pm

OK here is an example of how to do it.
Code: Select all
      $userButtons[] = array('label' => 'Custom Export', 'call_back_fun' => array(&$this,'customExport'), 'pass_id_array' => true, 'update_html' => false, 'no_update' => true);
      $this->Editor->setConfig('userButtons',$userButtons);

Code: Select all
   function customExport($info)
   {
      $this->Editor->sqlFilters = "id in ('".implode("','",$info)."')";
      $_SESSION['mate_custom_export'] = $this->Editor->exportInfo();
      $this->Editor->sqlFilters = null;
      $this->Editor->formatWhereClause();
      $this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'window.location="'.$_SERVER['PHP_SELF'].'?export=1&custom=1";');
   }


and then in the construct in the export section you'll need to replace
Code: Select all
               echo $this->Editor->exportInfo();

with
Code: Select all
            if(isset($_GET['custom']))
            {
               echo $_SESSION['mate_custom_export'];
               $_SESSION['mate_custom_export'] = '';
            }
            else
            {
               echo $this->Editor->exportInfo();
            }


Because the user button callback is all done with ajax it makes this a two step process. First we generate the csv information and store it in a session variable and send some javascript (window.location=...) back to the browser. This then allows the stored csv info to be echoed back to the browser and exported.
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 18 guests

cron