Hi, I try to get through connector, but I lack documentation. I’m not able to do it with existing one, I was trying $conn->event->attach, $gridConn->render_sql, etc… Simply I can not do it
My problem is: I have a grid, I want to send its data to two separate MySQL tables. Let’s say - collumns 0 and 1 of grid to table1 and columns 2 and 3 of grid to table 2.
How should I do it?
And vice versa, I want to get data from table1 to populate columns 0 and 1 of grid, and data from table 2 to populate columns 2 and 3 of grid.
Saving is more complicated, as you need to do 2 save calls, you can define custom function through
function myupdate($action){
//custom code here
}
$conn->event->attach("beforeProcessing", "myupdate")
and in myupdate function exec necessary calls ( directly through db interface )
There are two phone numbers. Suppose I want to make two tables, one with contact, as it is, but instead of phone numbers I want to keep in “phone_1” and “phone_2” just primary index from second table “phones”, where there is appropriate number. So in “phones”, there is primary index “p_i” and “number”.
Let’s say like this.
“Contact”…“Phones”
id fname lname company e-mail phone_1 phone_2…p_i …number
…0…1…0…987 654
…2…1…345 678
…3…0…2…123 456
What I want to do - in my contact table I don’t want to see indexes, but real numbers. And when I change/delete/insert the number, I want to update “phones” table as well.
1.) If I understood well, render_sql is responsible for uploading data from sql to grid, render_table is responsible for uploading data from db to grid?
2.) In above mentioned tutorial, I can edit grid directly, or via form. That means, I have watch just grid for changes, and those changes apply to connector and connector applies them to db?
3.) As for double save - connector.php consist of code for connecting to db, and then is
$gridConn = new GridConnector($res,“MySQL”);
$gridConn->render_table(“contact”,“contact_id”,“fname,lname,company,email”);
I tried this:
function myupdate($action){$id = $action->get_id();
$val1 = $action->get_value(“Phone_1”);
$gridConn->mysql_query(“INSERT INTO Test (phone) VALUES {$val1}”);
$action->success();}
$gridConn->event->attach(“beforeProcessing”, “myupdate”);
(1) both render sql and render table works in similar way, they will take data from db and output it in the components format, as xml ( or as json ) . The only difference is the sql code which is provided in command ( render_sql ) or autogenerated ( render_table )
(2) Yep. You can have different connectors for form and grid, but in most cases it doesn’t have sense to duplicate data saving logic.
(3) In your code
$gridConn->mysql_query("INSERT INTO Test (phone) VALUES {$val1}");
must be
global $gridConn;
$gridConn->sql->query("INSERT INTO Test (phone) VALUES {$val1}");
and be sure that event->attach is placed before render_table
[code]function myupdate($action){
global $gridConn;
$id = $action->get_id();
$phone1 = $action->get_value(“Phone_1”);
$gridConn->sql->query("INSERT INTO test (phone_1) VALUES ($phone_1)");
$action->success();
}
$gridConn = new GridConnector($res,“MySQL”);
$gridConn->event->attach(“beforeProcessing”, “myupdate”);
$gridConn->render_table(“contacts”,“contact_id”,“fname,lname,company,email”);[/code]
Also, I’m not sure about “$phone1 = $action->get_value(“Phone_1”);” - you have not this field in list of connector’s fields, so I’m not sure from which it will come - it must be one of fields defined in render_table or set as userdata on client side.
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan