File upload in a Dialog calls default ajax call

File upload in a Dialog calls default ajax call

Link to test case: https://editor.datatables.net/examples/extensions/import.html
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: I have a Dialog with 4 fields. One of the field is the "upload" field type. The Dialog has two buttons "Create" and "Cancel". I want to upload a CSV file and parse using the Papaparser locally (in browser) as given in the example and only when the user clicks "Create" send the data to the backend with the Ajax call. However I am unable to achieve this and followed the example of CSV file Import.

I do not hit the parser at all in the ajax call, but rather it calls the default url from the form. How to disable the the default ajax call and divert it to make ajax call when button is pressed and parse the file contents locally? Please help.

{
            label: "</f:verbatim><h:outputText value="Import CSV File:"/><f:verbatim>",
            name: "fileUpload",
            type: "upload",
            ajax: function(files,done){
                debugger;
                console.log("Papaparser ajax call");
                Papa.parse(files[0], {
                    header: true,
                    skipEmptyLines: true,
                    complete: function (results) {
                        console.log("Papaparser complete");
                        if ( results.errors.length ) {
                            console.log( results );
                        }
                        else {
                            console.log("Success");
                        }
 
                        // Tell Editor the upload is complete - the array is a list of file
                        // id's, which the value of doesn't matter in this case.
                        done([0]);
                    }
                });
            }
}

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    I've just tried a little example here: http://live.datatables.net/liyogamo/1/edit .

    The ajax function specified for the upload field type is indeed called.

    What version of Editor are you using? The ability to use the ajax option for the upload field type was added in 1.9.

    Allan

  • andreas.heckwolf@menturagroup.comandreas.heckwolf@menturagroup.com Posts: 12Questions: 4Answers: 0

    Hello Allan,
    Here are the version info about our Data Tables in the project.
    DataTables v1.10.12
    DataTables Editor v1.6.1
    Please let me know whether they are compatible, if not can you suggest an alternative.
    Thanks
    Andreas

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394
    Answer ✓

    What version of Editor are you using? The ability to use the ajax option for the upload field type was added in 1.9.

    It seems that you need to upgrade your Editor.

  • andreas.heckwolf@menturagroup.comandreas.heckwolf@menturagroup.com Posts: 12Questions: 4Answers: 0

    Hello,
    After updating to latest version everything works as expected.
    Thanks
    Andreas

Sign In or Register to comment.