⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

"set_relation" with HUGE table goes bad. Try this picker.



Kenta Saito

Kenta Saito
  • profile picture
  • Member

Posted 22 March 2012 - 14:55 PM

Version:
grocery_CRUD_v1.2.zip

"set_relation" is pretty good.
But... the relation table's row count was huge, it can't render select's options.

My solution is not simple yet, but it can be one of the ways I think.

[attachment=79:picker.png]

[indent=1]
Original:
Render a select with options. (every rows in table)

Mine:
Open modal dialog what return the selected row's primary key. (same as nomal list interface)[/indent]

A example below is "Customer calls Employee".


diff -ru --strip-trailing-cr CodeIgniter_2.1.0.orig/application/controllers/examples.php CodeIgniter_2.1.0/application/controllers/examples.php
--- CodeIgniter_2.1.0.orig/application/controllers/examples.php 2012-03-15 21:27:32.000000000 +0900
+++ CodeIgniter_2.1.0/application/controllers/examples.php 2012-03-22 23:28:28.000000000 +0900
@@ -2,6 +2,44 @@

class Examples extends CI_Controller {

+ function picker_close($id)
+ {
+ echo '<script type="text/javascript">';
+ echo "window.returnValue = '$id';";
+ echo 'self.close();';
+ echo '</script>';
+ }
+
+ function employee_picker()
+ {
+ $crud = new grocery_CRUD();
+
+ $crud->set_table('employees');
+ $crud->set_relation('officeCode', 'offices', 'city');
+ $crud->display_as('officeCode','Office City');
+
+ $crud->unset_add();
+ $crud->unset_edit();
+ $crud->unset_delete();
+ $crud->add_action('Pick', 'dummy.png', 'examples/picker_close');
+
+ $output = $crud->render();
+ $this->_example_output($output);
+ }
+
+ function _employee_picker($value, $primary_key)
+ {
+ $script =
+ "ret = showModalDialog('".site_url('examples/employee_picker')."');".
+ "if (ret != null) $('[name=salesRepEmployeeNumber]').val(ret);"
+ ;
+ $data = array(
+ 'content' => 'Pick Employee',
+ 'onclick' => $script
+ );
+ return form_input('salesRepEmployeeNumber', $value, 'style="width:100px;"').'&nbsp;'.form_button($data);
+ }
+
function __construct()
{
parent::__construct();
@@ -83,6 +121,8 @@
$crud->set_subject('Customer');
$crud->set_relation('salesRepEmployeeNumber','employees','{lastName} {firstName}');

+ $crud->callback_field('salesRepEmployeeNumber', array($this, '_employee_picker'));
+
$output = $crud->render();

$this->_example_output($output);