Edit/View Dialog from other (relational) table than the one displayed in grid

QuestionsEdit/View Dialog from other (relational) table than the one displayed in grid
Jeremy asked 8 years ago

I have 2 tables for contacts. One is the "main" one with the primary data (eg ID, Name, Email). I want to display this in the grid (with inline editing). This works well. But I want to generate a simple dialog (as in the Dialog Layout demo) that shows a popup dialog containing the fields from the "details" table (eg ID, address, phone, website, etc).

Seems like this is possible, but it's not clear to me what the syntax would be. Any and all help appreciated. Thanks!

4 Answers
Abu Ghufran answered 8 years ago

If you want view only dialog:

You can use select_command to have a join query of both tables and select all fields as grid columns.
You can hide / show certain grid column on list view and view dialog using following code:

$col["show"]["list"] = true;
$col["show"]["view"] = false;

If you want them in edit dialog and change them on editing, you will follow the same join query work as above but on edit you need to bind on_update event handler.
In that callback function you can override the default edit behavior of grid and run 2 queries based on posted data.

For details, refer demos/editing/custom-events.php

Jeremy answered 8 years ago

Thanks for the quick response – that is a good suggestion. I was stuck thinking there would be a way to have 2 queries in one instance of the grid. Silly.

However, I am getting a not so helpful error message. It displays an empty grid with an error dialog:

Query is Select booking.cal_calendar.event_date , booking.cal_events.name, booking.cal_events.description from booking.cal_calendar join booking.cal_events on booking.cal_calendar.event_id = booking.cal_events.id where booking.cal_calendar.event_date > "201711"
{"page":1,"total":1,"records":"3","rows":[{"event_date":"2017-02-16","name":"Duke Performances Presents Talib Kweli","description":""},{"event_date":"2017-02-17","name":"Duke Performances Presents Talib Kweli","description":""},{"event_date":"2017-03-26","name":"An Evening with Loudon Wainwright III","description":""}]}

Seems as though we have all the data we need to fill the grid. There's no actual Error presented, just the query and the results. I've tried with "inner join" and just "join" with the same results.

Any suggestions on how to get more info on what is going wrong?

Abu Ghufran answered 8 years ago

Hi,

I think all you need now is to comment out the echo / print debug calls.

Its basically breaking the JSON due to query output before json data.

Jeremy answered 8 years ago

Ah – I guess that was a dumb mistake. I had that in there bc my query worked on mysql cmdline, but not in the code. Discovered the problem was I had added a semi-colon, but the code appends one so it's redundant.

Ok, I removed my echo'd query and it is working. Thank you.

Your Answer

20 + 11 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?