Hook a Lookup table for select box control type

Hook a Lookup table for select box control type

darshitj2darshitj2 Posts: 10Questions: 2Answers: 0

Hi All,

Is there any way i can hook a lookup table for some columns in the Datatables ?

Replies

  • darshitj2darshitj2 Posts: 10Questions: 2Answers: 0

    Hi @allan could you throw some light on this?

  • darshitj2darshitj2 Posts: 10Questions: 2Answers: 0

    @allan could you please help me with this?

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406
    edited March 2017

    Not sure what exactly you mean with lookup table. If it is simple options to select for a field in Editor read from a database, a file or hard-coded then these examples will help you out:
    - read from database
    https://editor.datatables.net/examples/advanced/joinLinkTable.html
    - hard coded options:
    https://editor.datatables.net/examples/simple/fieldTypes.html

    if you want to be able to enter search text into the "look up" field use the selectize plug-in instead of the select field.

    code example:
    JavaScript - the options database contains up to 20,000 records; a maximum of 15 records is sent to the front end based on user entry of the department name. The user cannot create a department (create: false).

    fields: [ {
                    label: "For:",
                    name:  "contract.govdept_id", //render gov_name, govdept_name
                    type: "selectize", 
                    opts: {
                        create: false,
                        maxItems: 1,
                        maxOptions: 15,
                        openOnFocus: false,
                        allowEmptyOption: false,
                        placeholder: "Please select a Department"
                        }
                }
    

    server side:

    Field::inst( 'contract.govdept_id' )->validator( 'Validate::notEmpty', array('message' => $msg[0]) )
                    ->options( Options::inst()
                        ->table('govdept, gov')
                        ->value('govdept.id')
                        ->label( array('gov.name', 'govdept.name', 'gov.type', 'gov.regional_12') )
                        ->render( function ( $row ) {               
                            return $row['gov.name'].' / '.$row['govdept.name'].' ('.$row['gov.regional_12'].'); '
                                    .renderGovType($row['gov.type']); 
                        } )
                        ->order( 'gov.name asc' )
                        //where clause MUST be a closure function in Options!!!
                        ->where( function($q) {
                            //only govs that are already clients can be selected
                            $q ->where( function($r) {
                                $r ->where('gov.is_client', 1 );
                                $r ->where('govdept.gov_id', 'gov.id', '=', false); //join
                            });
                        } )
                    ),
    
  • darshitj2darshitj2 Posts: 10Questions: 2Answers: 0
    edited March 2017

    Thanks @rf1234 fro quick response.

    We generally use Datatables to show data. Here I am talking about a scenario where i want to edit the existing data.
    Suppose there is one column 'CITY' in Datatables. Now i want to a value in a select box format rather than plain text.
    So i just want to know is there any way i can bind the list of cities to each cell in that column ('CITY') and whatever the current value of cell is, it will be the selected value.

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    Use Editor with inline editing and the options instance as described above. That will allow you to set the value for each cell in the column also with a select box I guess. Should be no problem at all.

  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin

    Hi darshitj2 - are you using Editor at all for this? I don't actually see an Editor license for your account, so I'm guessing not?

    Suppose there is one column 'CITY' in Datatables. Now i want to a value in a select box format rather than plain text.

    With Editor you would use a select field, probably with a leftJoin as rf1234 suggests.

    If you aren't using Editor, then you'd need to modify whatever code base you are using to do the edit to support what you need.

    Allan

  • darshitj2darshitj2 Posts: 10Questions: 2Answers: 0
    edited March 2017

    Thanks @allan @rf1234 for your suggestions.
    I am new to it.

    Can anyone of you tell me how to get license for editor and further?

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394
This discussion has been closed.