I have a join / select box issue.

I have a join / select box issue.

indymxindymx Posts: 63Questions: 3Answers: 0

I have a editor with a select list element that populates as expected for a New item. However, for and existing record, it populates, and now I need to have it set the SELECTED with what is currently in the row. I'm just not seeing it.

the fields I am working with are "schedule.sponsor" and "links.title".

$out = Editor::inst($db, 'schedule', 'id')
    ->fields(
        Field::inst('schedule.date'),
        Field::inst('schedule.sponsor'),
        Field::inst('links.title')
    )
    ->leftJoin('links', 'links.id', '=', 'schedule.sponsor')
    ->process($_POST)
    ->data();

if (!isset($_POST['action'])) {
    $out['link'] = $db
        ->select('links', 'id as value, title as label', array('sponsor' => '1'), 'id')
        ->fetchAll();
}
echo json_encode($out);

(function ($) { $(document).ready(function () { var editor = new $.fn.dataTable.Editor({ ajax : 'php/table.schedule.php', table : '#schedule', fields : [ { "label" : "Date", "name" : "schedule.date", "type" : "datetime" }, { "label" : "Sponsor", "name" : "schedule.link", "type" : "select" } ] }); // Activate the bubble editor on click of a table cell $('#schedule').on('click', 'tbody td:not(:first-child)', function (e) { editor.bubble(this); }); var table = $('#schedule').DataTable({ dom : 'Bfrtip', ajax : 'php/table.schedule.php', columns : [ { data : null, defaultContent : '', orderable : false }, { "data" : "schedule.date" }, { "data" : "schedule.link" } ], select : true, lengthChange : false, buttons : [ { extend : 'create', editor : editor }, { extend : 'edit', editor : editor } ], initComplete : function (settings, json) { // Populate the site select list with the data available in the // database on load editor.field('schedule.link').update(json.link); } }); }); }(jQuery));
create table links
(
    id int auto_increment
        primary key,
    title text null,
    constraint links_id_uindex
        unique (id)
)

create table schedule
(
    id int(4) auto_increment
        primary key,
    date datetime not null,
    sponsor int(1) not null
)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Could you show me the data that the server is sending back to the client when loading the table? Normally what you are seeing will happen if value Editor is told to edit is actually the label rather than the actual value.

    Its also worth noting that Editor has an Options class which can be used to help populate the list of options rather than needing to use initComplete yourself.

    Allan

  • indymxindymx Posts: 63Questions: 3Answers: 0

    Sure, heres the json data for one record

    135:{DT_RowId: "row_343",…}
        DT_RowId:"row_343"
            links:{title: "Steel Shoe Nationals"}
            title:"Steel Shoe Nationals"
        schedule:{date: "2017-08-26 23:59:59", rider_meeting_time: "16:00:00", practice_time: 
            "16:30:00",…}
            cancelled:"0"
            date:"2017-08-26 23:59:59"
            event_location:"Mid-America Speedway"
            heat_time:"19:00:00"
            info:"<p>Round 2 of the Steel Shoe Nationals. &nbsp;Classes include:&nbsp;Pro 450 DTX Single, Pro 450/505 Framer, Pro Super Twins, and Speedway.</p>↵"
            practice:"0"
            practice_time:"16:30:00"
            raceevent:"1"
            rider_meeting_time:"16:00:00"
            sponsor:"18"
            title:"Rd. 2 of the Steel Shoe National Series and the US vs. Canada Speedway Shootout"
    
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Could you also show me json.link that is used to populate the select list please? Or better yet, a link to the page?

    Thanks,
    Allan

  • indymxindymx Posts: 63Questions: 3Answers: 0

    Drop me an email and I'll send you a link and password.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    Sent :)

This discussion has been closed.