multiple editor instances depending on field value for different types?

multiple editor instances depending on field value for different types?

schnittoschnitto Posts: 5Questions: 3Answers: 0

Hey guys, I really hope someone can help me here. Here is a small screenshot link of the "movie rating" database and its tables: imgur.com/a/JNrWc
I chopped everything down to the very problem so you wont get confused by all other columns and tables etc.
I want to use the DataTables and Editor Plugin to have one DataTable instance in which I can see all kind of movies in the mysql database. I have 4 different types of movies and every one has its own specific information and because of that I couldnt just put all into one big table. Here is my problem:

I want to use the Editor with his functionality to edit existing movie ratings, create new ones and delete some. So far so good. First, I put all fields of every table you can see in the Editor instance in the php-file in which I define the fields, joins etc. I've read, that I could use dependencies to hide and show specific fields I want the user to fill in or not but that wouldnt "remove" the field instances from the editor in the php-file.
My problem is, I dont know how to achieve the functionality to only change the fields of the given movie genre the movie has and not to get empty/null filled entries in all 4 movie genre tables.

For example:
I have the comedy movie-rating "trump is president 2k17" and many other movie-ratings in the animation table. The both other tables "thriller" and "horror" are empty.
When I look in the DataTable, it shows me all entries of the database perfectly, so one comedy rating and many "animation-rating" entries. I select the comedy movie rating and press EDIT.
In the Edit Instance, I change a column value and press save. Now here is the problem. Editor updates the entry perfectly without any problem, BUT for all other 3 left movie-rating genres I receive
empty inserts so I have entries with a bunch of NULL values. How can I make the Editor initializing work, so dependant on the genre field of the Editor, it will only edit/create/remove for the specific genre
and it fields and not for all tables.

I had the idea to make a editor instance for every movie-genre so every one of the 4 editors would only have the columns he needs for the table, but I dont know how to do the connection in the javascript part, where
you have to make the DataTable and its columns data AND the editor with the editor instance dependant on the movie genre.

I would be really happy if someone could help me out here. I try to provide as many information as necessary. Maybe I'm thinking too complecated, but I really dont know how to get this thing working
for 4 different types/tables of the movie.

Thanks for your time and help.

This question has accepted answers - jump to:

Answers

  • rf1234rf1234 Posts: 3,116Questions: 91Answers: 429
    Answer ✓

    Hi schnitto,

    I guess I had a similar issue: Based on a condition I wanted to avoid Editor to update a field (or multiple fields). I found a solution in this post:
    https://datatables.net/forums/discussion/41102

    If you do the same for all fields in the table this might work for you.

    Otherwise you could do a custom build delete of the null rows after editing based on an Editor event.

  • allanallan Posts: 64,587Questions: 1Answers: 10,679 Site admin
    Answer ✓

    I think there are two ways you can approach this - which one to use will depend a bit on how you want the interface to work:

    1. Use a single Editor instance on the client-side which does the show / hide of the fields you mentioned - based on the genre selected. On the server-side use events to make the fields editable or not ($editor->field('name')->set( false ) disables write for a field to the database for example). You'd make all the fields for the other tables not settable.
    2. Possibly slightly easier is to have a different Editor instance for each genre - submitting the different fields to different server-side scripts. The key difficulty here is in selecting the genre. You'd probably need to have it that you can't change the genre after it has been created (since changing genre would require a change in the Editor instance being used).

    Allan

  • schnittoschnitto Posts: 5Questions: 3Answers: 0

    Thanks alot for your help. It worked great!

This discussion has been closed.