How to render filename instead of image in editor upload working example?

How to render filename instead of image in editor upload working example?

CapamaniaCapamania Posts: 233Questions: 81Answers: 5

I'm struggling to render the 'file name' of the document I uploaded with the editor upload function. So instead of the image like in the working example https://editor.datatables.net/examples/advanced/upload.html I would like to render the 'file name'. In the editor function it is working fine, but in the table I still get the file ID. By any chance, is somebody seeing what I'm missing?
Or how would the display function look like in the working example if I just want to have the file name ... e.g. test.csv

    editor = new $.fn.dataTable.Editor( {
        ajax: "...upload.php",
        table: "#datatable",
        fields: [ {
                label: "Data Source:",
                name: "document",
                type: "upload",
                display: function ( file_id ) {
                     return table.file( 'files', file_id ).filename;
                  },
                clearText: "Clear",
                noImageText: 'No document'
            }
        ]
    } );
 
    var table = $('#datatable').DataTable( {
        dom: "Brt",
        ajax: "...upload.php",
        columns: [
            {
                data: "document",
                display: function ( file_id ) {
                    return file_id ?
                            table.file( 'files', file_id ).filename :
                    'No document';
                  },
                title: "Document"
            }
        ],
        select: true,
        buttons: [
            { extend: "edit",   editor: editor }
        ]
    } );

It should work corresponding to https://datatables.net/reference/api/file%28%29

This question has an accepted answers - jump to answer

Answers

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5
    Answer ✓

    I need to use 'render' instead of 'display' in the $().DataTable() function ... :-) Now it's working ...

    var table = $('#datatable').DataTable( {
        dom: "Brt",
        ajax: "...upload.php",
        columns: [
            {
                data: "document",
                render: function ( file_id ) {
                    return file_id ?
                            table.file( 'files', file_id ).filename :
                    'No document';
                  },
                title: "Document"
            }
        ],
        select: true,
        buttons: [
            { extend: "edit",   editor: editor }
        ]
    } );
    
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Hi,

    Thanks for posting back with your solution. You are correct - columns.render is the option to use in DataTables for this.

    Allan

This discussion has been closed.