I have a join / select box issue.
I have a join / select box issue.
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
This discussion has been closed.
Answers
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 useinitComplete
yourself.Allan
Sure, heres the json data for one record
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
Drop me an email and I'll send you a link and password.
Sent