Преглед на файлове

Makes max rows persistence after refreshing jq grid.

jmontoyaa преди 7 години
родител
ревизия
f4a033d912
променени са 2 файла, в които са добавени 31 реда и са изтрити 4 реда
  1. 15 3
      main/inc/ajax/model.ajax.php
  2. 16 1
      main/inc/lib/display.lib.php

+ 15 - 3
main/inc/ajax/model.ajax.php

@@ -1,16 +1,28 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use ChamiloSession as Session;
+
 //@todo this could be integrated in the inc/lib/model.lib.php + try to clean this file
 require_once __DIR__.'/../global.inc.php';
 
 $libpath = api_get_path(LIBRARY_PATH);
 
 // 1. Setting variables needed by jqgrid
-
 $action = $_GET['a'];
-$page = intval($_REQUEST['page']); //page
-$limit = intval($_REQUEST['rows']); //quantity of rows
+$page = (int) $_REQUEST['page']; //page
+$limit = (int) $_REQUEST['rows']; //quantity of rows
+
+// Makes max row persistence after refreshing the grid
+$savedRows = Session::read('max_rows_'.$action);
+if (empty($savedRows)) {
+    Session::write('max_rows_'.$action, $limit);
+} else {
+    if ($limit != $savedRows) {
+        Session::write('max_rows_'.$action, $limit);
+    }
+}
+
 $sidx = $_REQUEST['sidx']; //index (field) to filter
 $sord = $_REQUEST['sord']; //asc or desc
 $exportFilename = isset($_REQUEST['export_filename']) ? $_REQUEST['export_filename'] : '';

+ 16 - 1
main/inc/lib/display.lib.php

@@ -1302,10 +1302,25 @@ class Display
         if (!empty($extra_params['rowList'])) {
             $obj->rowList = $extra_params['rowList'];
         }
-        //Sets how many records we want to view in the grid
+
+        // Sets how many records we want to view in the grid
         $obj->rowNum = 20;
         if (!empty($extra_params['rowNum'])) {
             $obj->rowNum = $extra_params['rowNum'];
+        } else {
+            // Try to load max rows from Session
+            $urlInfo = parse_url($url);
+            if (isset($urlInfo['query'])) {
+                parse_str($urlInfo['query'], $query);
+                if (isset($query['a'])) {
+                    $action = $query['a'];
+                    // This value is set in model.ajax.php
+                    $savedRows = Session::read('max_rows_'.$action);
+                    if (!empty($savedRows)) {
+                        $obj->rowNum = $savedRows;
+                    }
+                }
+            }
         }
 
         if (!empty($extra_params['viewrecords'])) {