{hero}

file()

Since: Editor 1.5

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 or uploadMany). The information returned 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:

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 $.fn.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 = $('#example').DataTable( {
        dom: "Bfrtip",
        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';
                }
            }
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );
} );

Related

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