left join only for getting values for new entrys
left join only for getting values for new entrys
I have tables for
- invoices
- users
- approval for invoices (holding data wihch users have to approve each invoice; might be multiple users).
when opening an invioce, I also call a list of all required approvers with their status, date and so on. I also add a button for additional approvals. In the pop-up I want that only people are listed, that are not already necessary as approvers for this invoice.
Therefore I also already have a view in my sql, that is giving the names of those potential additional users ('V_NeueFreigeber').
Everything works fine but one thing: In the pop-up for new users ALL potential users for all invoices are named.
Here the server-code:
<?php
include( "../lib/DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
session_start();
$selectedStapelname = $_SESSION["selectedStapelname"];
$selectedINP_ID = $_SESSION["selectedINP_ID"];
Editor::inst( $db, 'V_Freigaben', 'ID_freigabe')
->fields(
Field::inst( 'V_Freigaben.ID_freigabe' )->set(false),
Field::inst( 'V_Freigaben.INP_ID' ),
Field::inst( 'V_Freigaben.Stapelname' ),
Field::inst( 'V_Freigaben.freig_person' )
//here i get the potential new approvers; this field always returns nothing/null
->options( Options::inst()
->table( 'V_NeueFreigeber' )
->value( 'rights_PID' )
->label( 'NamePers' ) )
->validator( Validate::dbValues() ),
Field::inst( 'V_NeueFreigeber.NamePers' ),
Field::inst( 'V_Freigaben.freig_person2' )->set(false)
//here i get the already established approvers for showing them in the list
//in the end freig_person and freig_person2 are the same field!!!
->options( Options::inst()
->table( 'V_users' )
->value( 'PID' )
->label( 'Namen' ) )
->validator( Validate::dbValues() ),
Field::inst( 'V_users.Namen' ),
Field::inst( 'V_Freigaben.freig_zahlsp_grund' )
)
->where( 'V_Freigaben.Stapelname', $selectedStapelname )
->where( 'V_Freigaben.INP_ID', $selectedINP_ID )
->leftJoin( 'V_users', 'V_users.PID', '=', 'V_Freigaben.freig_person' )
->leftJoin( 'V_NeueFreigeber', 'V_NeueFreigeber.INP_ID = V_Freigaben.INP_ID AND V_NeueFreigeber.Stapelname = V_Freigaben.Stapelname COLLATE Latin1_General_100_CI_AS AND V_NeueFreigeber.rights_PID = V_Freigaben.freig_person', '', '' )
->process( $_POST )
->json();
Here the html (the relevant parts)
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "../../../../../../../DataTables/Editor-PHP-1.9.6/controllersKontura/freigabe_PID_St_INP.php",
table: "#liste_freigaben",
fields: [
{ label: "Freigeber", name: "V_Freigaben.freig_person", type: "select", placeholder: "Bitte wählen"
}, { label: "INP ID", name: "V_Freigaben.INP_ID", default: "__INP_ID__", type: "hidden"
}, { label: "freig_angefordert_von", name: "V_Freigaben.freig_angefordert_von", default: "__thisPID__", type: "hidden"
}, { label: "Stapelname", name: "V_Freigaben.Stapelname", default: "__Stapelname__", type: "hidden"
}, { label: "Begründung", name: "V_Freigaben.freig_angefordert_wie"
} ],
formOptions: { inline: { onBlur: 'submit'}}
} );
How can I achieve this?
Thanks
Max
This question has an accepted answers - jump to answer
Answers
Hi Max,
What you need to do for this is make use of
dependent()
. The values of the select field depend on the state of other fields in the form, so when the form is in that state (start edit or user edits values) the client-side will need to refresh the list of options. Typically that is done by making an Ajax request to the server to get the list of options (to another PHP script which will query the database based on the state of the form).That approach is taken in this blog post. While it isn't exactly the same as your case, the principles there can be applied.
Let me know how you get on with that,
Allan
Hi Allan,
first of all: I LOVE this editor+datatable!!! Great stuff and amazing possibilities!
And I will dig into the dependencies on another occasion, I have a future problem this will be necessary for!
BUT: I think in this case this is not the best solution, I do not need an update of values depending from other fields. The possible filed-values can be selected when building the datatable/editor.
I think it must be something like:
i tried with options: ['max', 'kurt', 'allan'], but that didnt change anything - I still got ALL possible values from V_Freigaben.freig_person; max, kurt and allan were neglected.
Thanks for your help!
max
You mean you just have a static list of options that can be used for all rows?
looks correct to me, assuming that the SQL names are correct.
Just before the
->process( $_POST )
can you add->debug(true)
, then can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.Regards,
Allan
Hi Allen, thanks again. Yes this works but calls ALL rows, I would need to limit them with something like
->where( 'V_Freigaben.Stapelname', $selectedStapelname )
->where( 'V_Freigaben.INP_ID', $selectedINP_ID )
Is that possible?
By the way some little critics, maybe the view of a beginner is helpful for optimizing some points. Nothing of high importance, but small anoying things...:
* in the explanations (manual etc) sometimes it is not clear (for beginners) where code should go to - e.g. into php, server-side, ...
* in some cases the blue box in the right top corner with "PHP" or "javascript" is on top of bit of the code, which can then not be read.
* in my "account" i find a list of all questions I ever have had. All of them are marked open, although apart from this one I accepted an answer in each of them.
Max
Sorry should be
->where( 'V_NeueFreigeber.Stapelname', $selectedStapelname )
->where( 'V_NeueFreigeber.INP_ID', $selectedINP_ID )
Is this what you are looking for?:
Thanks for the feedback!
Regards,
Allan
And also, why does it have a "hover" state, which I interpret as meaning it is somehow actionable on click?
Hi Allan, that would be what I need.
For some reasons with that solution, and also with
there are no results displayed at all.
Just to make sure it is not a problem with the sql or similar I made up a controller like this
and the datatable to fit, and this works like a charm...
ad feedback: Happy to hear I did not offend!
ad 2: Cant you implement a first (empty) line that is always there?
Legacy... It used to show a dialogue box with extra information. Needs to be removed.
Can you show me the JSON response from the server when the data is loaded please? It should contain the SQL executed, which would be useful here.
That would be one option. It just feels a bit redundant. When I read tangerine’s comment I was wondering about hiding the tag on hover over the code block.
Allan
Hi Allan,
I diged into "getting the json response" (I am learning a lot here...) and found this:
But this does not include the sql executed...what else can i do...I can send you the user+pw for the site as pm, if you would be ready to help me further?
regards
Max
sorry debug was not firing as I had it after "process"...sorry as I mentioned I am quite a beginner. Here now the query:
which seems strange too me as I have both conditions in there:
when changing the order, it always only uses the second/last where-statement. If I have only one where-statement, this one is used, but also then it says "IS NULL".
ALso when putting a fixed value like '123' instead of $selectedStapelname, the debugger always cmoes up with "IS NULL".
thanks
Max
Hi Max,
There is indeed something odd going on there. Do you have it inside a closure function perhaps? It doesn’t appear to be from the code above, but I don’t have the complete listing, so I might be missing something. Could you show me the unabbreviated file please?
Also the unabbreviated JSON would be useful as well since you are using those variables elsewhere too.
Thanks,
Allan
I did send you all files invovled (i think so...) as a pm...
and here the full debug-part of the json. In the "Main query" the where-condition works:
can I move this from "free community support" to the "paid" one??
Hi Max,
That's it moved over. To be honest, the category of the discussion doesn't actually make any difference. Priority support threads such as yours get highlighted in red for me regardless of category .
Thanks for the files!
I think I might see the issue - specifically in the chaining of the
where
method. Could you try the following for me please?That is a little different from the behaviour of
Editor->where()
method where they can be chained for additional conditions. I think that should be changed in the code...Could you try that and let me know how you get on with it please?
Thanks,
Allan
Here the working solution for multiple conditions in the options: