Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81728

stateLoadCallback causing strange error on nextPage click and leading zeros on page info

$
0
0

Hi,

I've uploaded a config report ref: afebor

I'm saving and loading state info to and from a MySql source via ajax using typical ajax methods. Everything works perfectly well except for two strange glitches.

  1. The "info"string is displaying like:- Showing 01 to 025 of 52 entries (Notice leading zeros)
  2. The "pagingType": "full_numbers" is working OK except for the NEXT button. When clicked, the console reports the error:- TypeError: w is undefined

My Save and Load code in the dataTables script is as follows:-

var tbl = $('#' + tableId).DataTable( {
  stateSave: true,
                    stateSaveCallback: function (settings, ssData) {
                        $.ajax({
                            url: '" . URL . "myaccount/saveview/' + tableId,
                            data: ssData,
                            dataType: 'json',
                            type: 'POST',
                            success: function(){}
                        });
                    },
                stateLoadCallback: function (settings, callback) {
                        $.ajax( {
                            url: '" . URL . "myaccount/loadview/' + tableId,
                            dataType: 'json',

                            success: function (json) {
                                callback(json);
                            }
                        });
                }

My php code in my controller is:-

public function loadView($table_id)
    {
        $json = UserModel::getMyTableView($table_id);

        echo $json; 
    }
    public function saveView($table_id)
    {
        $json = json_encode($_POST);

        // if we don't clean the POSTed data then "columns":[{"visible":"false" wont work on stateLoadCallback(). it needs to be "columns":[{"visible":false
        $clean = str_replace('"false"', 'false', $json); 

        echo UserModel::saveView($table_id, $clean);
    }

and in my model, the code is:-

    public static function getMyTableView($table_id)
        {
            $sql = "SELECT state_save FROM user_views WHERE user_id = :user_id AND table_id = :table_id LIMIT 1";

            $database = DatabaseFactory::getFactory()->getConnection();

            $query = $database->prepare($sql);
            $query->execute(array(':user_id' => Session::get('user_id'), ':table_id' => $table_id));

            $row = $query->fetch();

            if (empty($row))
            {
                return json_encode(array());
            } else {
                return $row->state_save;
            }
        }

        public static function saveView($table_id, $post)
        {

            $sql = "INSERT INTO user_views (user_id, table_id, state_save) VALUES (:user_id, :table_id, :state_save) ON DUPLICATE KEY UPDATE table_id = :table_id, state_save = :state_save";

            $database = DatabaseFactory::getFactory()->getConnection();
            $query = $database->prepare($sql);
            //$query->execute(array(':table_id' => $post['table_id'], ':column_list' => $post['column_list'], ':user_id' => Session::get('user_id')));
            $query->execute(array(':table_id' => $table_id, ':state_save' => $post, ':user_id' => Session::get('user_id')));

            if ($query->rowCount()) {
                    return 'Layout Saved';
            }
            return 'The layout could not be saved';
        }

I've ran the debugger on my table and received no errors or warnings and I can't find anything that refers to this sort of problem

Thank you


Viewing all articles
Browse latest Browse all 81728

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>