Edit Functionality Disabled after Adding display property in Editor

Edit Functionality Disabled after Adding display property in Editor

ecbs@cbs.grecbs@cbs.gr Posts: 2Questions: 1Answers: 0
edited January 13 in Free community support

Edit button was working until I added display property in Editor. Here is the code:

 editor = new $.fn.dataTable.Editor({
        table: tableID,
        fields: { label:  fieldName ,
                                 name:  fieldID , 
                                 type : fieldtype , 
                                 ajax: "../upload?id=" + fieldID + "&elid=" + elid , 
                                 display: function(id){return editor.file( "attachments", id ).filename;} }

        }
    });

    var table = $(tableID).DataTable({
        dom: "Bfrtip",//Buttons/f/r/t/info for entries/pagination
        data: obj,
        select: true,
        columns: { data: fieldID },
        searching: false,
        buttons: [
            {extend: "create", editor: editor},
            {extend: "edit", editor: editor},
            {extend: "remove", editor: editor}
        ]
    });

Server Side json response to ajax call:

    return "{\"files\":{\"attachments\":{\"" + origfilename + "\":{\"filename\":\"" + origfilename + "\",\"web_path\":\"\\/upload\\/1.png\"}}},\"upload\":{\"id\":\"" + origfilename + "\"}}\n";

I added display property so that the name of the file is displayed when the file is uploaded in the editor window. That was successful but when I try to edit a row that was there before:

I get this error:

dataTables.editor.js:147 Uncaught Unknown file table name: attachments

when I choose a row and click 'edit'

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 52,290Questions: 1Answers: 7,965 Site admin

    Are you able to give me a link to the page in question so I can debug it please?

    Also does this happen on create or only on edit?

    Allan

  • ecbs@cbs.grecbs@cbs.gr Posts: 2Questions: 1Answers: 0

    Hi Allan,

    I'm afraid I can't because it is in work environment.
    In comparison with this example:

    https://editor.datatables.net/examples/advanced/upload.html

    I haven't implemented the render property and the ajax call in Data Table. Are those necessary? They weren't necessary before adding the display property in the Editor. Now the edit button throws this error. Only the edit button and only for the rows that are already there, not for the new ones that I create when the page is loaded.

    The attachments table that is referenced in the error, is returned from the rest controller and successfully displays the name of the file when it is uploaded.
    But when it comes to edit a row in a fresh loaded page it throws this error.
    It cannot find the attachment table. But to come across an attachments table and not recognize it the only way is through rest controller I suppose
    and I don't understand what changes when I add the display property in the editor!

    When I don't have the display property it doesn't need to access the Rest controller and When I add display property it needs to access the Rest controller to edit the row???

    Is this because I haven't implemented the the ajax call and the render method in dataTable?

    The only server side code implemented is a Rest Controller for the upload ajax request. Then the only difference from the example is that I haven't implemented the ajax and render properties in dataTable. My leader would rather not use the ajax property for the dataTable for speed reasons I suppose and because it was not necessary before adding the display property to the editor.

Sign In or Register to comment.