type error on image load

type error on image load

ashiersashiers Posts: 101Questions: 8Answers: 7

I'm duplicating example: http://editor.datatables.net/examples/advanced/upload.html

As I have the edit dialog form open on a record I'm able to load an image file, however, as I attempt to update the dialog form using the UPDATE button the dialog form just hangs there and doesn't go away like it should. The table loads with the image ok, but FireBug reports:

TypeError: table.file(....) is undefined          upload.jsp (line: 64, col 46)
'<img src="/editors'+table.file( 'images', file_id ).web_path+'"/>' :

Following is my JavaScript:

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "../jsp/uploadfile.jsp",
        table: "#example",
        fields: [ {
                label: "First name:",
                name: "first_name"
            }, {
                label: "Last name:",
                name: "last_name"
            }, {
                label: "Image:",
                name: "image",
                type: "upload",
                display: function ( file_id ) {
                    return '<img src="/editors' + table.file( 'images', file_id ).web_path + '"/>';
                },
                clearText: "Clear",
                noImageText: 'No image'
            }
        ]
    } );
 
    var table = $('#example').DataTable( {
        dom: "Bfrtip",
        ajax: "../jsp/uploadfile.jsp",
        columns: [
            { data: "first_name" },
            { data: "last_name" },
            {
                data: "image",
                render: function ( file_id ) {
                    return file_id ? '<img src="/editors' + table.file( 'images', file_id ).web_path + '"/>' : null;
                },
                defaultContent: "No image",
                title: "Image"
            }
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );
} );

On submission of the record update the returned JSON string in as follows:

{"data":[{"DT_RowId":"row_38","first_name":"Amy","last_name":"Shumer","image":"7"}]}

which is correct in its content. I can't figure out why I'm getting the TypeError message. Please advise.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Could you run your page through the debugger and let me know what the debug code is please? The files() method was introduced with Editor 1.5.

    Allan

  • ashiersashiers Posts: 101Questions: 8Answers: 7

    I tried the debugger but it just hangs. I think its because I'm just running things locally. I don't have it online yet. This particular problem may have to wait until I do have it online.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Weird! The only other thing I can suggest is to check that table actually exists (use a breakpoint or some debugging statements) and that table.files exists (it should with all the latest versions).

    Allan

This discussion has been closed.