Hello volks,
i've just got the editor licence and i'm struggeling to get my table showing the information i want it to.
The first screenshot shows my current table, second shows the edit select field.
I want to have the label of the selected value from the DB in the table by default not the value.
I do also have a readonly field which has options defined which is also only showing the value not label.
**Status **should display the label of the current status in the table (shows int) and select on edit (this works)
**Type **should display the label and does not need to be edited
here is my js:
var editor; // use a global for the submit and return data rendering in the examples
var table; // use global for table
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: {
url: 'libs/basic/datatables/orderposition.php',
data: {
"collectiveinvoice": 141
}
},
table: "#datatable",
fields: [
{
label: "Status:",
name: "status",
type: "select"
},
{
label: "Beschreibung:",
name: "comment",
type: "ckeditor",
opts: {
toolbarGroups: [
{ name: 'forms', groups: [ 'forms' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
{ name: 'links', groups: [ 'links' ] },
{ name: 'insert', groups: [ 'insert' ] },
{ name: 'styles', groups: [ 'styles' ] },
{ name: 'colors', groups: [ 'colors' ] },
{ name: 'tools', groups: [ 'tools' ] },
{ name: 'others', groups: [ 'others' ] },
{ name: 'about', groups: [ 'about' ] }
],
removeButtons: 'Source,Save,Templates,NewPage,Preview,Print,Cut,Copy,Paste,PasteText,PasteFromWord,Find,SelectAll,Scayt,Replace,Form,Checkbox,TextField,Radio,Textarea,Select,Button,ImageButton,HiddenField,Subscript,Superscript,CreateDiv,BidiLtr,BidiRtl,Language,Anchor,Image,Flash,Smiley,SpecialChar,Iframe,Font,About,Maximize'
}
}, {
label: "Menge:",
name: "quantity"
}, {
label: "Preis:",
name: "price"
}, {
label: "Steuer:",
name: "tax",
type: "select"
}
]
} );
// Disable KeyTable while the main editing form is open
editor
.on( 'open', function () {
table.keys.disable();
} )
.on( 'close', function () {
table.keys.enable();
} );
// Activate an inline edit on click of a table cell
$('#datatable').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this, {
// Submit on leaving field
onBlur: 'submit'
} );
} );
table = $('#datatable').DataTable( {
dom: "<'row'<'col-sm-4'l><'col-sm-4'B><'col-sm-4'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'p>>",
ajax: {
url: 'libs/basic/datatables/orderposition.php',
data: {
"collectiveinvoice": 141
}
},
order: [[ 1, 'asc' ]],
columns: [
{ data: "id" },
{ data: "type" },
{ data: "status" },
{ data: "comment" },
{ data: "quantity" },
{ data: "price" },
{ data: "tax" }
],
select: false,
buttons: [
// Export Button
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
},
]
} );
} );
here is server side php:
Editor::inst( $db, 'collectiveinvoice_orderposition' )
->where( 'status', 0, '>' )
->where( 'collectiveinvoice', $_REQUEST['collectiveinvoice'] )
->fields(
Field::inst( 'id' )->set(false)->validator( 'Validate::unique' )->validator( 'Validate::numeric' ),
Field::inst( 'status' )->options( function () {
return array(
array( 'value' => '0', 'label' => 'gelöscht' ),
array( 'value' => '1', 'label' => 'aktiv' ),
array( 'value' => '2', 'label' => 'deaktiviert' ),
);
}),
Field::inst( 'quantity' )
->validator( 'Validate::numeric' )
->getFormatter( 'Format::toDecimalChar' )
->setFormatter( 'Format::fromDecimalChar' ),
Field::inst( 'price' )
->validator( 'Validate::numeric' )
->getFormatter( 'Format::toDecimalChar' )
->setFormatter( 'Format::fromDecimalChar' ),
Field::inst( 'tax' )->options( Options::inst()
->table( 'taxkeys' )
->value( 'value' )
->label( 'value' )
),
Field::inst( 'comment' ),
Field::inst( 'type' )->set(false)->options( function () {
return array(
array( 'value' => '0', 'label' => 'Manuell' ),
array( 'value' => '1', 'label' => 'Artikel (Kalk)' ),
array( 'value' => '2', 'label' => 'Artikel' ),
array( 'value' => '3', 'label' => 'Perso' ),
);
}),
Field::inst( 'file_attach' )->set(false),
Field::inst( 'perso_order' )->set(false)
)
->process( $_POST )
->json();
In addition, i want to display buttons based on the DB values of "file_attach" and "perso_order" so that they only show and have a reference in them to the db field, how would one do that? Or in other words how do i add a custom field to the table anyways (which is readonly)?
Thanks for this great tool!
Regards