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

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

BjornHaBjornHa Posts: 14Questions: 3Answers: 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: 54,897Questions: 1Answers: 8,605 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: 14Questions: 3Answers: 0
    edited June 1

    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: 14Questions: 3Answers: 0
    edited June 1

    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: 14Questions: 3Answers: 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: 54,897Questions: 1Answers: 8,605 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: 14Questions: 3Answers: 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: 54,897Questions: 1Answers: 8,605 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: 16Questions: 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: 54,897Questions: 1Answers: 8,605 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: 16Questions: 3Answers: 0

    Yes, that would be great; thank you Allan!

  • allanallan Posts: 54,897Questions: 1Answers: 8,605 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: 16Questions: 3Answers: 0

    <3

  • ideaxmeideaxme Posts: 16Questions: 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: 54,897Questions: 1Answers: 8,605 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: 14Questions: 3Answers: 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: 54,897Questions: 1Answers: 8,605 Site admin
    Answer ✓

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

    Allan

Sign In or Register to comment.