Standalone editor load ajax

Standalone editor load ajax

borconiborconi Posts: 56Questions: 19Answers: 1

Hi.

How can I load ajax data for a standalone editor?

  manual_upload = new $.fn.dataTable.Editor( {
        ajax: "manual_upload.php",
        table: "#none",
        fields: [ {
                label: "Company:",
                name:  "company",
                type:"readonly"
                }, {
                label: "Location:",
                name:  "short_add",
                type:"readonly"
                },
                {
                label: "Job:",
                name:  "long_description",
                type:"readonly"
                },
                {
                label: "Rep. pos.:",
                name:  "rep_pos",
                type:"select"
                },
                {
                label: "Rep. name:",
                name:  "rep_pos_name"
                }
        ]
    } );
.....
manual_upload.s.ajax='./manual_upload.php?schid='+schedule_id;
manual_upload.buttons( [{
                label: "Close",
                fn: function () { 
                    manual_upload.close();
                    return false;
                    }}]);
manual_upload.title("Manual Upload");   
manual_upload.edit();

This opens the editor correctly but the data is never populated.
I need to have it in a standalone environment so it's not associated to any table. Do I need to manually make a ajax call?

Thank you.

This question has an accepted answers - jump to answer

Answers

  • bacalovbacalov Posts: 22Questions: 3Answers: 0

    Hi "borconi",

    Any luck on this subject?

    Thank's!

  • allanallan Posts: 61,814Questions: 1Answers: 10,123 Site admin
    Answer ✓

    Editor won't load data when an editing action is triggered (that is something that might come in a future version). Instead, the data must already be at the client-side. In the case of a standalone Editor, that means that it needs to be in the HTML. The documentation for this is available here.

    Allan

  • borconiborconi Posts: 56Questions: 19Answers: 1

    Sorry haven't logged in for a few days so I didn't see the comments.

    I workaround the limitation by using an ajax call and manually populating the fields, which is triggered by the editor "open" event something like this:

    $.ajax({
        type: "GET",
        url: './manual_upload.php?schid='+schedule_id,
    
        success: function(newOptions){
            t = JSON.parse(newOptions);
            manual_upload.field( 'rep_pos' ).update( t.options );  
            manual_upload.field( 'rep_pos' ).val( t.data[0]["rep_pos"] );  
            manual_upload.field( 'company' ).val( t.data[0]["company"] );  
            manual_upload.field( 'short_add' ).val( t.data[0]["short_add"] );  
            manual_upload.field( 'long_description' ).val( t.data[0]["long_description"] );  
            manual_upload.field( 'rep_name' ).val( t.data[0]["rep_name"] );  
            manual_upload.field( 'handheld_date' ).val( t.data[0]["handheld_date"] );  
            manual_upload.field( 'Satisfaction' ).val(null);
    },
        error: function(response){ }
        });
    

    Not the most elegant but it works.

This discussion has been closed.