Is_select_mode() causes render_table to use internal row IDs

Trying to get some help with this with more narrowed subject as to what seems to be the issue. $conn-render_table(table_name) works great and updates are written to the database table EXCEPT when the render_table follows the is_select_mode() evaluation, as suggested in the Connector guide (see [url]Basic Loading DHTMLX Docs)

I’ve logged the data and using $conn-render_table(table_name) alone, allows the Grid to take user updates and store them back to the database table (this also displays the valid record ID from the database). However, when this is set up within an if…else statement such as the one below (taken directly from the samples page on the DHTMLX website), it uses an internally generated row ID (gr_id) which does NOT update the database table.

  1. This is supposed to work - as per the documented sample, so not sure what is wrong. Oh so many hours spent, trying to figure this out. :frowning:
  2. If it’s not going to work, is there some other way to get the true record ID so I can manually generate the UPDATE command?

Would love to get some clues as to how to resolve this issue so I can use the Grid widget.

Attached are the complete files to reproduce this issue, including the .sql files to produce the two tiny tables.

The zipped attachment includes:

[]the html file[/]
[]the php data file[/]
[]the .sql file to create the tables[/]
[]the .log file with the results from first commenting out the if($conn->is_select_mode()){… statement so only the $conn->render_table(“tableA”); is available. Then I uncomment out the if($conn->is_select_mode()){… and run the grid the again, this time you can see the row ID becomes an internal ID, and appears like it should’ve updated the database table, but it actually does NOT [/]

test_grid.zip (3.34 KB)

Try to change the command like next

$conn->render_sql("Select *, tableA.id as masterid from tableA, tableB WHERE tableA_field3 = tableB_id", "masterid","tableA_id, tableA_field1, tableB_field1, tableA_field2");

The name of id field

  • must be selected in the sql code
  • must have a simple name ( the same name as it will have in resultset ). Complex names (like a.id) may work or may not works - it depends on used DB type and DB driver.

Thank you - this at least is updating, but is wiping out the link between the two tables (tableA_field3 now gets set to zero). Looks like there’s some shifting of the columns. Perhaps I’m better off specifying each column rather than using ‘*’ in the render_sql?

I’ll play with this some more to try and get it to work.

Thank you.

Got this to work, however it’s very too dependent on column order rather than observing the actual column labels.

Would you be able to provide how I’d write the UPDATE myself - rather than relying on the connector’s use of the render_table?

Thank you in advance.

While I’d still like to see how to write my own UPDATE code with the row ID, I’m posting how this was able to get working via the use of the render_sql for the two tables and the render_table() for the single table updates, so hopefully others can benefit…

The two key requirements:

  1. the key id from the main table must be part of your render_sql() to that it’s populating in the grid. You need this so references will be using the actual record id of the database table and not the internal row ID of the grid;
  2. the columns have to be in the exact same order in the render_sql as they are in the table that will be referenced in the render_table(). So if your render_sql is joining two tables, you’ll need to make sure any columns you display from the secondary table are at the very end of all the columns from the primary table, otherwise the render_table() will not work, as the data is blindly assigned to each column in the same order as it was listed in the render_sql.

Below is the modified is_select_mode() paragraph that got this to work correctly:

 if($conn->is_select_mode()){
	//code for loading data
	$conn->render_sql("Select tableA_id, tableA_field1, tableA_field2, tableB_field1  from tableA, tableB WHERE tableA_field3 = tableB_id", "tableA_id","tableA_id, tableA_field1, tableA_field2, tableB_field1");
	
}else {
	$conn->render_table("tableA","tableA_id","tableA_id, tableA_field1, tableA_field2");// data configuration 
}

You can use onBeforeUpdate server side event to place a custom code for data saving operations
docs.dhtmlx.com/doku.php?id=dhtm … date_event

Also, check docs.dhtmlx.com/doku.php?id=dhtm … erver-side