StateLoad Via Button Click

StateLoad Via Button Click

marklmarkl Posts: 9Questions: 2Answers: 0

Hello everyone. I'm trying to load the saved state of my datatables with a button click but I'm having some issues. Basically, I click a button to get the saved state (oData) via ajax from the database and I want to refresh the table with the results. I'm running version 1.10.1 and here's the button click function:

/* btnLoadSavedState click event */
$('#btnLoadSavedState').click(function () {
    resetValidation();

    var $form = $('#load-savedstate-form');

    // Load preset form
    $form.validate().form();

    if ($form.valid()) {

        // Get selected value from the dropdownlist
        var selectedValue = $('#selectedSavedState').val();

        // get the saved state in the database
        $.ajax({
            type: 'POST',
            url: baseurl + 'MyController/LoadSavedState',
            data: { url: $(location).attr('href'), id: selectedValue },
            success: function (data) {  // The data object contains the oData
                if (data.retBool == true) {
        $.jnotify('State loaded successfully!', 'success');
                    // Any ideas?

                } else {
                    $.jnotify('Function(btnLoadSavedState) load failed!', 'error');
                }

            },
            error: function () {
                $.jnotify('Function(btnLoadSavedState) ajax call failed!', 'error');
            }
        });

    }
    return false
});

Answers

  • marklmarkl Posts: 9Questions: 2Answers: 0
    edited November 2014

    Update - I changed the ajax call to the code below but it doesn't work. It reloads the table but it's not setting the hidden columns , sort order ...

        $.ajax({
            type: 'POST',
            url: baseurl + 'MyController/LoadSavedState',
            data: { url: $(location).attr('href'), id: selectedValue },
            success: function (data) {  // The data object contains the oData
                if (data.retBool == true) {
        $.jnotify('State loaded successfully!', 'success');
    
    
                        /* If returned oData is not an empty string, then parse it */
                        if (data.oData != '') {
                            var oSettings = JSON.parse(data.oData);
                        }
    
                        oTable.oSettings = oSettings;
                        oTable.fnDraw(false);
    
                } else {
                    $.jnotify('Function(btnLoadSavedState) load failed!', 'error');
                }
    
            },
            error: function () {
                $.jnotify('Function(btnLoadSavedState) ajax call failed!', 'error');
            }
        });
    
This discussion has been closed.