editor.ajax.reload is not a function

editor.ajax.reload is not a function

dynasoftdynasoft Posts: 446Questions: 69Answers: 3

Hi

I'm trying to call a reload on an editor table as per below:

var editor = null;

jQuery(function($){

LoadTypes();

    setInterval( function () {
        editor.ajax.reload(null, false);
    }, 10000 );
});
}

function LoadTypes() {

editor = new $.fn.dataTable.Editor({
...

}

But keep getting error 'editor.ajax.reload is not a function'. Thanks.

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    ajax.reload() is a DataTable API method, not an Editor method.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Thanks. Is there an equivalent or Editor?

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    for Editor

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Got it to work w/ this example: https://editor.datatables.net/examples/extensions/rowReorder. Thanks.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Still have an issue. I load data in select fields when eidor object gets created. How can I reload/recreate the editor object? If I try and call the same initial code I get error https://datatables.net/manual/tech-notes/3

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    Did you follow the steps in the technote?
    https://datatables.net/manual/tech-notes/3

    It has the troubleshooting steps to resolve the problem.

    Kevin

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Hi

    Yes I did but that page covers working w/ DataTable not the Editor object created via editor = new $.fn.dataTable.Editor. I'm able to reload the table either via dataTable.ajax.reload(null, false); or by setting dataTable.destroy(); and calling the javascript that loads the table and sets editor again but the code only hits reloading the table and not recreating the editor object where my select's are located. Even if I set editor = null, the creation of the editor object is not reached. I know that because in that part I have razor code which gets hit in VS only on loading the page but not on calling that js function that sets the table and creates the editor object. Any idea? Thanks.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3
        editor = new $.fn.dataTable.Editor({
    
            ajax: '/CallSettings/CRUDCallTypes/' + intContTpe2.toString() + '/' + lngContIdx2.toString(),
            table: '#tblDataTable',
            fields: [ {
                    label: '@(lbls.lblCallType)*:',
                    name: 'TypeName'
                }, {
                    label: '@(lbls.lblCallGroup)*:',
                    name: 'GroupName',
                    type: 'select',
                    options: [
                        @if (ViewBag.ConfigCallGroupsList != null)
                        {
                            strTp = "\"-- " + lbls.lblSelectOption + " --\", ";
                            if (ViewBag.ConfigCallGroupsList.Count > 0)
                            {
                                foreach (var item in ViewBag.ConfigCallGroupsList)
                                {
                                    strTp = strTp + "\"" + item.Text + "\", ";
                                }
                            }
                            strTp = strTp.Substring(0, strTp.Length - 2);
                        }
                        else
                        {
                            strTp = "\"-- " + lbls.lblSelectOption + " --\", ";
                        }
                        @Html.Raw(strTp)
                        ],
                    def: '-- @(lbls.lblSelectOption) --'
                }
            ]
        });
    
  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    If I place code above in a function and call itlike so:

        editor.destroy();
        editor = null;
        dataTable.destroy();
        dataTable = null;
        MyFunction();
    

    The ViewBag razor code is never reached as the cursor just stays on 'editor = new $.fn.dataTable.Editor' and the GroupName select is never updated wit hthe content of the ViewBag.

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    Editor doesn't have an API reload or destroy it.

    I'm not sure I understand the problem you are trying to solve. Please explain what you are trying to do/solve so we can try to provide a solution.

    Kevin

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Hi. I have a select called GroupName whose options need to be reloaded after initially loading the table via a MVC view.

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin

    Ah - in that case use field().update() to update the list of options for a select.

    Allan

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Thanks

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    How can I set tis with an array:

                    var arrAttr = new Array(3)
                    arrAttr[0] = "'arm1'";
                    arrAttr[1] = "'arm2'";
                    arrAttr[2] = "'arm3'";
    

    Thanks.

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin

    I'm afraid I don't understand the question. You've defined an array there. Running that in the console shows:

    arrAttr
    (3) ["'arm1'", "'arm2'", "'arm3'"]
    

    Allan

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3
    var flags = ['USA','Brazil','Germany','Canada'];
    editor.field('GroupName').update( [
        $.each(flags, function(key, value) {
            var yourkey = key + 1;
        })
    ] );
    

    This returns a single string with all flags whereas I need each flag extracted separately as individual array member.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3
                    editor.field('GroupName').update( [ 
                        $.each(flags, function(index, value) {
                            flags
                        })
                    ] );
    

    or

                    editor.field('GroupName').update( [ 
                        $.each(flags, function(index, value) {
                            value
                        })
                    ] );
    

    return a single line/select option with all flags rather than one select option per array member

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Please see screenshot.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    var flags = ['USA','Brazil','Germany','Canada'];

    That is a Javascript array, not a string.
    I don't really understand what you want.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Hi, the string is how editor displays the array. Please see the screenshot. I need as explained one array member per select option.

    This also gives the same (wrong) behaviour:

                    editor.field('GroupName').update( [ 
                        flags
                    ] );
    
  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    This
    editor.field('GroupName').update( [
    'USA','Brazil','Germany','Canada'
    ] );
    gives the expected result, as per below:

    But I can't set the update method with the individual members as its something that can't be hardcoded, but taken from an array.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    The array is populated from an ajax call. I guess another way of putting this is how can I set the values for this update method and not hardcode them?

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    edited April 2019

    This is an array:
    var flags = ['USA','Brazil','Germany','Canada'];

    You have this:

    editor.field('GroupName').update( [
        flags
    ] );
    

    This is passing an array inside an array to the update method, which I don't think you want. I think you want this:

    editor.field('GroupName').update( flags );
    

    Note I removed the [] surrounding flags.

    Kevin

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    It's been a long day. Thank you very much. That worked.

This discussion has been closed.