Options does not use preset selections

Options does not use preset selections

sharkowolfsharkowolf Posts: 21Questions: 9Answers: 0

Good day,

Dear developers,

Another simple question about the work of DataTables, with which I ask you to help:

I use the example from the link https://editor.datatables.net/examples/advanced/parentChild.html

The example contains the following feature, as a selection by option:

{
     label: "Site:",
     name: "users.site",
     type: "select",
     placeholder: "Select a location"
}

I modified it for myself and it works great

    Editor::inst( $db, 'services', 's_id' )
        ->field(
            Field::inst( 'services.s_id' ),
            Field::inst( 'services.q_id' )->set(Field::SET_CREATE)->setValue('2')->get(false),
            Field::inst( 'services.sg_id' )->options( 'sgroups', 'sg_id', 'sg_n' )->validator( 'Validate::dbValues' ),
            Field::inst( 'sgroups.sg_id' ),
            Field::inst( 'sgroups.q_id' ),
            Field::inst( 'sgroups.sg_n' )
        )
       ->leftJoin( 'sgroups', 'sgroups.sg_id', '=', 'services.sg_id' )
       ->leftJoin( 'queue', 'queue.q_id', '=', 'sgroups.q_id' )
       ->where(function ($q) {

    $q->where( 'sgroups.sg_id',  '2', '=');
    $q->and_where( 'services.sg_id', '17' , '=' );

}

The problem that was clarified is as follows. In my sgroups table, 3 rows belong to one group and the other 3 rows belong to another group. Division occurs by the value of the sgroups.sg_id field. When the Editor displays the table, everything is displayed correctly, taking into account the selections. But when I start adding a new element - it contains not only the first 3 lines, but also the second ones, which is not correct (since the selection is set only on the first 3 lines). This is due to the following code:

Field::inst( 'services.sg_id' )->options( 'sgroups', 'sg_id', 'sg_n' )->validator( 'Validate::dbValues' ),

Which for some reason is not subject to the selection rules:

$q->where( 'sgroups.sg_id',  '2', '=');
$q->and_where( 'services.sg_id', '17' , '=' );

I ask you to suggest:
1. How to select not all values ​​for Options, but with selection by values ​​that are set in where?
2. How can I see the final query that is compiled to execute the DataTables?

Sincerely,
Andrey

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 54,687Questions: 1Answers: 8,553 Site admin
    Answer ✓

    Hi Andrey,

    The Options class has its own where method that you'd need to apply to your instance.

    If the options can change per row, then you need to use dependent() to have Editor make an Ajax call to the server to get the list of options for the row that is currently being edited.

    Allan

  • sharkowolfsharkowolf Posts: 21Questions: 9Answers: 0

    Allan,

    Thank you very much for your prompt reply.

    Function -> where (function ($ q) {
    helped.

    I can't stop admiring the powerful and handy DataTables engine.

    Thanks!

    Sincerely,
    Andrey

Sign In or Register to comment.