Upload example - having some trouble
Upload example - having some trouble
lincolncbennett
Posts: 25Questions: 11Answers: 1
in Plug-ins
Hi Allan, just trying to replicate the example Upload plugin to try. Not sure what I'm doing wrong, hopefully something simple.
Any help would be greatly appreciated.
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
"ajax": "examples/php/staff2.php",
"table": "#staff",
"fields": [
{
"label": "name",
"name": "staff.name"
},
{
"label": "title",
"name": "staff.title"
},
{
"label": "Info:",
"name": "staff.image",
"type": "upload",
"display": function ( val, row ) {
return val && row.image.webPath ?
'<img src="'+row.image.webPath+'"/>' :
'No image';
}
}
]
} );
$('#staff').DataTable( {
"dom": "Tfrtip",
"ajax": "examples/php/staff2.php",
"columns": [
{
"data": "staff.name"
},
{
"data": "staff.title"
},
{
"data": "image",
"defaultContent": "No image",
"render": function ( d ) {
return d.webPath ?
'<img src="'+d.webPath+'"/>' :
null;
}
}
],
"tableTools": {
"sRowSelect": "os",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
} );
} );
}(jQuery));
<?php
/*
* Editor server script for DB table staff
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "../../php/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'staff' , 'id')
->fields(
Field::inst( 'staff.name' ),
Field::inst( 'staff.title' ),
Field::inst( 'staff.info' ),
Field::inst( 'staff.image' )
->upload(
Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' )
->db( 'image', 'id', array(
'fileName' => Upload::DB_FILE_NAME,
'fileSize' => Upload::DB_FILE_SIZE,
'webPath' => Upload::DB_WEB_PATH,
'systemPath' => Upload::DB_SYSTEM_PATH
) )
),
Field::inst( 'image.fileName' )
)
->leftJoin( 'image', 'image.id', '=', 'staff.image' )
->process( $_POST )
->json();
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
problem solved
Hi,
Sorry I missed this at the time. What was your resolution in the end?
Allan
I have a table at the moment which uses the Custom display controller for editing basic client info and I have successfully added the upload feature to add a PDF file containing client info. In each table row I also have 7 inline active check boxes, so as to monitor progression tasks required for each client. I have only just added the upload plugin so am going to have a play around and then post the code if I cant get to work correctly. Thanks Allan for this awesome plugin.
below shows the changes I made to the code above and then it worked just fine.
Sounds good - thanks for posting back :-)
Allan
Hi Allan further to my second post, I seem to be having some issues.
I had 2 inline active checkboxes and was using the Custom display controller for editing. Since adding the Upload plugin, with a link in each row to the uploaded file, I cannot see the checkboxes ticked in the table but see them checked when opening the child editor. The only other change was defining the database table as required for upload left join, in php. Sorry the code below is long. Any help would be appreciated.
I don't immediately see anything wrong with the above code. Are you able to give me a link to the page or use the DataTables debugger so I can see what is happening?
Thanks,
Allan
ofuhoy
Found the fault,the issue was in defining the fields. snippets below show changes made to table code. Server script was fine.
Good to hear you got it sorted!
Allan