file()
Get information about an uploaded file.
Please note - this property requires the Editor extension for DataTables.
Description
This method is an alias of the file()
method which accepts exactly the same parameters and returns the same results. This alias is provided on the DataTables API for convenience in cases where it is easier to use the DataTables API methods rather than Editor.
Please refer to the file()
documentation for full details of this method.
Type
function file( table, id )
- Description:
Get information about an uploaded file that has been uploaded through Editor (
upload
oruploadMany
). The information returned is determined by how thedb()
method has been configured for theUpload
class on the server-side (if this has been used). Please see the PHP and .NET for details on this method.- Parameters:
Name Type Optional 1 table
No Database table name that holds information about the required file
2 id
No File identifier - i.e. the primary key value for the row that contains information about the required file.
- Returns:
Information about the selected file, or
undefined
if not found.
Example
Use file()
to display an image in a DataTable column and the Editor form:
$(document).ready(function () {
var editor = new DataTable.Editor({
ajax: '../php/upload.php',
table: '#example',
fields: [
{
label: 'First name:',
name: 'users.first_name'
},
{
label: 'Last name:',
name: 'users.last_name'
},
{
label: 'Image:',
name: 'users_files.fileId',
type: 'upload',
display: function (fileId) {
return '<img src="' + table.file('files', fileId).web_path + '"/>';
}
}
]
});
var table = new DataTable('#myTable', {
ajax: '../php/upload.php',
columns: [
{ data: 'users.first_name' },
{ data: 'users.last_name' },
{ data: 'users.phone' },
{ data: 'sites.name' },
{
data: 'users_files.fileId',
render: function (fileId) {
return fileId
? '<img src="' + table.file('files', fileId).web_path + '"/>'
: 'No image';
}
}
],
layout: {
topStart: {
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
}
},
select: true
});
});
Related
The following options are directly related and may also be useful in your application development.