files()

Since: Editor 1.5

Get information about multiple uploaded files.
Please note - this property requires the Editor extension for DataTables.

Description

The Editor upload and uploadMany field types provide the ability for an end user to upload files to a server, potentially storing information about the file on a database (this is not mandatory for the upload field types to work, but it is required for this method to return information about the available file).

    This method provides access to information about all uploaded files (unlike its counterpart `e-api file()` method which gives information about a single file).

    This can potentially be useful if you want to create an input option that will show the end user all previously uploaded files and allow them to select one or more files.

Type

files( [ table ] )

Get a list of files that have been previously uploaded via an Editor form (upload or uploadMany). The information available for each file is determined by how the db() method has been configured for the Upload class on the server-side (if this has been used). Please see the PHP and .NET for details on this method.

Parameters:

Returns:

object:
If a table parameter is given, the object returned will contain an entry for each file that has been uploaded via the Editor upload fields. The object keys are the primary key values for the file's database entry. An error is throw if the requested table object cannot be found.

        If a `table` parameter is not given, an object is returned where the keys are the table names that have been defined for use on the server-side and the value an object as described above for individual tables.

Example

Use files() to log all files available from the database table documents (done in initComplete here):

$(document).ready(function () {
	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="' + editor.file('files', fileId).web_path + '"/>'
						: 'No image';
				}
			}
		],
		select: true,
		layout: {
			topStart: {
				buttons: [
					{ extend: 'create', editor: editor },
					{ extend: 'edit', editor: editor },
					{ extend: 'remove', editor: editor }
				]
			}
		},
		initComplete: function () {
			console.log(editor.files('documents'));
		}
	});
});

Related

The following options are directly related and may also be useful in your application development.