uploadSince: Editor 1.5 Single file upload field. Please note - this property requires the Editor extension for DataTables. DescriptionThe ability to upload files is an important element in complex forms and data structures. The upload field type provides that ability to Editor by presenting an file upload control to the end user, giving them the option of uploading a single file for the field (the uploadMany field type allows multiple files to be assigned to a single field) The file upload is performed asynchronously to the main form - i.e. as soon as a file is selected, either via drag-and-drop or a standard file selection control, it is immediately uploaded to the server and the field will take a value that identifies the file (typically this is a database id for a row containing information about the file, but can also be any other identifying data such as a file name). This field value is then submitted as part of the standard form. The upload field type is supported on the server-side by the Upload class available in Editor's standard libraries (PHP | .NET). Please refer to the documentation for those libraries for how to configure the server-side scripts. Additionally, an overview of how to configure the upload field types on the client-side is available in the Editor manual. The remaining documentation here is concerned solely with detailing the options available for this field type. EventsThis field type can trigger the following events from the input element (field().input() ): upload.editor - Upload complete event - this should be used in place of a change event for this field type. The following parameters are passed in to the event handler:object event - The event objectAny value - File identifier from the server - normally a primary key value or a file name.
TypeThis option can be given in the following type(s): OptionsThis field type supports the following options (in addition to the default options): MethodsThis field type does not support any additional methods over the default methods. ExamplesDisplay an upload field type that displays an image: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | new $.fn.dataTable.Editor( {
ajax: "php/staff.php" ,
table: "#staff" ,
fields: [ {
label: "Image:" ,
name: "image" ,
type: "upload" ,
display: function ( val ) {
return '<img src="' +table.file( 'files' , fileId ).webPath+ '"/>' ;
}
},
]
} );
|
Disable drag and drop, and enable clearing current value: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | new $.fn.dataTable.Editor( {
ajax: "php/press.php" ,
table: "#press" ,
fields: [ {
label: "Press release PDF:" ,
name: "pdf" ,
type: "upload" ,
display: function ( val ) {
return table.file( 'files' , fileId ).fileName;
},
dragDrop: false ,
clearText: 'Remove file'
},
]
} );
|
Listen for an upload event: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | var editor = new $.fn.dataTable.Editor( {
ajax: "php/staff.php" ,
table: "#staff" ,
fields: [ {
label: "Image:" ,
name: "image" ,
type: "upload" ,
display: function ( val ) {
return '<img src="' +table.file( 'files' , fileId ).webPath+ '"/>' ;
}
},
]
} );
$( editor.field( 'image' ).input() ).on( 'upload.editor' , function (e, val) {
console.log( 'Image field has changed value' , val );
} );
|
|