two dataset a grid and a form master-detail relationship

Hello experts!

Once upon a time, there was two table in a mysql database called people and users. There is 1-n relationship between them. A user always linked into a people and a people could have 0 or one user account. There is a multiview(3 pages) with a grid and two forms in my app. The grid contains a list of people recorded into the people table (1st page). On a second page there is a form which linked into the grid editing people details. It works correctly. On the third page would be an other form which contains text fields for username and user level (defining the user rights) etc. If people has user account the form would be filled by data from the user table, if not, the form would be empty.

How should be implement the relationship between the user form and the people grid?

ps. Sorry about my terrible English


In my opinion the solutions that is used in the following sample will do:

You need to bind the people list with account form:


and define dataFeed property in the form config:

{view:“form”, id:“myform”, dataFeed:“accountdata.php”, elements:[…]},

When the cursor (selected item) in the list is changed, the request with “id” parameter (item id from people list) will be sent to teh server (dataFeed url).

It’s OK, but I read somewhere in the documentation of dhx.DataProcessor about if I want to insert record into connected table the key must be autoinc field. So the users table looks like this:

user_ID int(11) NOT NULL auto_increment,
people_ID int(11) NOT NULL,
username varchar(20) collate utf8_unicode_ci NOT NULL,
passwd varchar(40) collate utf8_unicode_ci NOT NULL,
level int(2) NOT NULL,

So the ID which will send is only foreign key.
dsUsrRights.php looks like this:

 <span class="syntaxdefault"><?php

    $form = new JSONDataConnector($res);

The issue is not clear enough. Please explain it in detail. Which component DataProcessor is connected to ?

You can define dataFeed as function, for complex data binding cases

{view:"form", id:"myform", dataFeed:function(id, data){ this.load("some.php?id="+data.people_ID); }, elements:[...]},

it allows to call sub-data script with any custom parameters

Also, in server side code you are using


while it is a legal call, it will work more stable if you provide full configuration

$form->render_table("{$cfg[‘sqlprefix’]}users", “…ID field…”,"…fields…");

I binded the form manually by the onafterselect event of the grid


But there ar 2 cases in the joined database:

Case 1: there is a record in the database and dsMyform.php returns with requested data in JSON form. In this case the code above works correctly, the form showing correct data.

Case 2: there isn’t any record in the database which requested and dsMyform.php returns: [] . I wait in this case the myform should be empty according to clear() method, but it contains last succesfully fetched data.

How can I clear the form when it gets empty data from its datasource?
I think I walking in a right direction but I will need some help :slight_smile: Thank you!

The code of form must do nothing if empty response was received from the server side.
Form will not clear itself, but will not load old as well.

If issue still occurs - please provide the config of form.elements
Also, are you using dhtmlx touch 1.0 or 1.2 ?

The form is on third page of a multiview so I think it is loaded only once during the loading of the whole page. So I must clear it’s content and try loading current data if exist or leave empty before showing it. The grid’s onafterselect event seems to be suitable for this.

+-----------------------------------------------------------------+ | Multiview contains 3 views | +----------1------------+----------2-----------+--------3---------+ | myGrid contains few | frmGrid contains | myform contains | | important information | detailed infromation | the login data | | about employes | of selected employee | if the selected | | | and can modify it's | employee can log | | | data (binded to grid)| in to the site | +-----------------------+----------------------+------------------+

The problem is that just few employee can login to the site. So myform often gets empty result from it’s datasource. In this case would highly desirable appearing blank form.

Can I force clearing the form?

Currently I’m using V1.2 of dhtmlx touch.

Unfortunately I still can’t reconstruct the same issue locally :frowning:

You can try to replace the
$$(‘myform’).setValues({ name:"", email:""});

where name and email - names of fields which you want to clear

I tried setValues method but had no success.

But after some investigation… I found a solution :sunglasses: :wink:
I can check the response immedietly after loading. Just should call the load method of the form in different way:

$$("mygrid").attachEvent("onafterselect",function(id){ $$('myform').load('dsMyform.php?action=get&id='+id, function(text,xml,http_request){ if (text =="[]") $$('myform').clear(); }); });
It does exactly what I want.

I have only one more question:

I dont know why, but it looks the load method sets the form values back to last successful loaded data in case of empty response. Is this a bug?


We have tried to reproduced the problem once again - it is not reproduced.

clear() removes all values from a form. And load() method sets only loaded data. Please make sure that response is correct and contains desired values.

The form is very simple:

password again

According to the password stored as MD5HASH in the database that isn’t in the response. So those two fields will be use for defining or changing the password but never will display that.

It is a testing db so here can I provide both example:
This is the wrong version:
This is the good version:


We have reproduced the issue. We will fix it in the next version. Currently please use your solution that works great.