Does optionsPair support notation "table.field" or just "field"?

Does optionsPair support notation "table.field" or just "field"?

BjornHaBjornHa Posts: 36Questions: 6Answers: 0

Looking to use field type "datatable", and have optionsPair with only field name working fine. When trying to address with table prefix it seems not to be working.
optionsPair: { value: 'docID' } is OK
optionsPair: { value: 'persons.ID' } is not OK

KR,
Bjørn Hasselberg

PS, managed to create an empty discussion with question "Hello", by misstake, but seems I can not remove it myself.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi Bjørn,

    Empty conversation gone now :).

    What does the JSON you are using to populate the options look like. Is persons an object? At the moment the optionsPair option doesn't do nesting support, so it would be looking for something like obj['persons.ID] there, rather than obj.persons.ID.

    Allan

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0
    edited June 2021

    The nested editing of persons works fine, it is only the correlation between the original DT table and the first level editor that is a problem.

    The Json for where persons is on the top level looks like:

    {
        "DT_RowId": "row_33",
        "persons": {
            "first_name": "Stefan",
            "last_name": "Gunbrant",
            "associationType": "6",
            "email": "stefan.gunbrant@pro4u.se",
            "mobile": "0733 41 42 16",
            "pro4uId": "5937",
            "initial": "STGU",
            "portalId": "177"
        },
        "associationtypes": {
            "associationType": "Partner"
        },
        "portal_users": {
            "display_name": "b8290DNuNL"
        }
    }
    

    Server side php:

    Editor::inst( $db, 'persons', 'ID' )
        ->fields(
            Field::inst( 'persons.first_name' ),
            Field::inst( 'persons.last_name' ),
            Field::inst( 'persons.associationType' )
                ->options( Options::inst()
                    ->table( 'associationtypes' )
                    ->value( 'ID' )
                    ->label( 'associationType' )
                ),
            Field::inst( 'associationtypes.associationType' ),
            Field::inst( 'persons.email' ),
            Field::inst( 'persons.mobile' ),
            Field::inst( 'persons.pro4uId' ),
            Field::inst( 'persons.initial' ),
            Field::inst( 'persons.portalId' )
                ->options( Options::inst()
                    ->table( 'portal_users' )
                    ->value( 'ID' )
                    ->label( 'display_name' )
                ),
            Field::inst( 'portal_users.display_name' )
        )
        ->leftJoin( 'associationtypes', 'associationtypes.ID', '=', 'persons.associationType' )
        ->leftJoin( 'portal_users', 'portal_users.ID', '=', 'persons.portalId' )
        ->where( function ( $q ) use ( $myPersonID ) {
            if ($myPersonID > 0) {
                $q->where( 'persons.ID', $myPersonID );
            } else {
                $q->where( 'persons.ID', $myPersonID, '>' );
            }
        } )
        ->process( $_POST )
        ->json();
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0
    edited June 2021

    Realising this was a bad example as persons.ID is not in the json... stupid example
    Have another with companies ... where the ID is included.
    Tried now to see if including persons.ID would resolve anything, but didn't.

    {
        "DT_RowId": "row_33",
        "persons": {
            "ID": "33",
            "first_name": "Stefan",
            "last_name": "Gunbrant",
            "associationType": "6",
            "email": "stefan.gunbrant@pro4u.se",
            "mobile": "0733 41 42 16",
            "pro4uId": "5937",
            "initial": "STGU",
            "portalId": "177"
        },
        "associationtypes": {
            "associationType": "Partner"
        },
        "portal_users": {
            "display_name": "b8290DNuNL"
        }
    }
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0

    Hi Allan,

    Many thanks for your reply yesterday (and for removing the empty question :) ).
    After some more investigations and realising that I have issues with options from the first layer of editor to the second, I will simplify the ajax response to one dimensional and not move on with nested editing at this point.
    That resolves the issue with optionsPair for me as of now.

    (It seems the options from ajax/JSON response in field type "datatable" does not appear at nested editor, data is fine, same ajax works with options in a "basic" datatable/editor setup, but this might be my usage of course)

    KR,
    Bjørn Hasselberg

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi Bjørn,

    Thanks for your extra details on this - I'm afraid I don't have an immediate answer. I know you said you've moved on, but if you come back to this, let me know and if possible send me an example and I'll look into it.

    Thanks,
    Allan

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0

    Hi Allan,

    The option for nested editing part I can gladly give you input on, with code example of what works and what doesn't for me. I can also give you URLs for ajax functionality for GET in our testsystem so you can see data/option that works for a normal setup, but not in a nested version.

    OK if I send it over in a PM?

    KR,
    Bjørn H

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi Bjørn,

    That would be ideal - yes please. If you click my user name and then the "Send message" button, that will come straight to me.

    Allan

  • ideaxmeideaxme Posts: 17Questions: 3Answers: 0

    It looks like the following line on 5894 of dataTables.editor.js does not support nesting:
    return val.indexOf(data[valueProp]) !== -1;

    valueProp can only be somethuing like 'id', not 'company.id'

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    @ideaxme - You are absolutely correct. Is that a problem for how you are using this? I can add that ability.

    Allan

  • ideaxmeideaxme Posts: 17Questions: 3Answers: 0

    Yes, that would be great; thank you Allan!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    That's it committed in and it will be in Editor 2.0.5, which I don't expect to be too far away!

    Regards,
    Allan

  • ideaxmeideaxme Posts: 17Questions: 3Answers: 0

    <3

  • ideaxmeideaxme Posts: 17Questions: 3Answers: 0

    Hi @allan , thank you for making that change in 2.0.5. Now the "set" in theDatatables as input control selects the currently selected item(s). However, I'm afraid the "get" on that control is not working for "table.field" notation in the optionsPair. Line 5890 of datatables.editor.js says

            get: function (conf) {
                var rows = conf.dt
                    .rows({ selected: true })
                    .data()
                    .pluck(conf.optionsPair.value)
                    .toArray();
                return conf.separator || !conf.multiple
                    ? rows.join(conf.separator || ',')
                    : rows;
            },
    

    The .pluck() does not support "table.field" notation. However, I was able to come up with a hacky patch by copying the fetchData function from elsewhere in the jquery.datatables.js and using it on line 7172 of jquery.datatables.js

                pluck: function ( prop )
                {
                    return this.map( function ( el ) {
                        return this.fetchData(el, undefined, prop);
                    } );
                },
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You are right - the pluck option doesn't do dotted object notation at the moment. I do have an enhancement bug to add that ability, but I'm afraid it isn't implemented yet.

    Allan

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0

    If it is possible to upVote Pluck for table.field notation, I would do so. It limits the usage quite a bit, only dealing with one dimensional table sets.
    /björn h

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Thanks for the upvote :). I've marked it has higher priority.

    Allan

  • ideaxmeideaxme Posts: 17Questions: 3Answers: 0

    Seems like can work around it by loading select options in controller instead of getting them by ajax.
    ->options( Options::inst()
    ->table( 'order_header' )
    ->value( 'id' )
    ->label( 'sales_order_number' ) )
    ->validator( Validate::dbValues() ),

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0

    Is the Pluck enhancement far away? (table.field notation)

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    It will likely come in DataTables 2, but that is a "it will ship when it is ready" type of release rather than a planned data.

    For the moment, for nested data you can call pluck() multiple times - e.g.:

    data.pluck('table').pluck('field')
    

    Allan

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0

    OK, I thought this was to get the optionsPair working for that same syntax 'table.field', waiting for that in nested DataTables ;)

    KR,
    Bjørn Hasselberg

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi Bjørn,

    Ah! Sorry - I missed the context that this is for the datatable field type. Yes, that does bump it up the priority list. I'll get back to you on this one :)

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi - little update on this. I've committed the change and I'm going to do a DataTables 1.12 release which will include this feature. I don't expect that release to be too far away.

    Allan

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0
    edited April 2022

    Many thanks,

    On a side note, the issue regarding options and file information that did not populate in nested datatable fields, is that on its way as well?
    As you provided me with good workarounds, this is not a problem as such for me.

    KR,
    Björn H

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi Björn,

    Apologies, you are going to have to remind me about that one. I found this discussion but can't recall what the outcome was!

    Allan

  • BjornHaBjornHa Posts: 36Questions: 6Answers: 0

    Hi Allan,

    I will mail the latest mail I have on that subject, I think it contains the history.

    KR;
    Björn H

Sign In or Register to comment.