leonam-carlos

Page LIMIT for Adianti

Oct 19th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.01 KB | None | 0 0
  1. /*
  2. Coloca no final da __contruct da TPage com TDatagrid, antes de chamar o método "parent::"
  3. */
  4.  
  5.         TScript::create("
  6.  
  7. var arr = [
  8.  {val : 5, text: '5'},
  9.  {val : 10, text: '10'},
  10.  {val : 20, text: '20'},
  11.  {val : 50, text: '50'},
  12.  {val : 100, text: '100'},
  13.  {val : 500, text: '500'},
  14.  {val : 1000, text: '1000'}
  15. ];
  16.  
  17. var value_selected = 20;
  18.  
  19. $('<label style=\"margin-left:10px; padding-left=10px; padding-right:10px; font-size: 12px;\">Qtde por página</label>').appendTo('.panel-footer:first');
  20. var sel = $('<select id=\"limit_page\">').appendTo('.panel-footer:first');
  21. $(arr).each(function() {
  22.    sel.append($(\"<option>\").attr('value',this.val).text(this.text));
  23. });
  24.  
  25. if (!!$.cookie('profile_limit_". self::$formName ."_per_page')) {
  26.    var select_actual = $.cookie('profile_limit_". self::$formName ."_per_page');
  27.    $('#limit_page').val(parseInt(select_actual));
  28.    $('#limit_page').change();
  29. }
  30.  
  31. $('#limit_page').on('change', function(){
  32.    value_selected = $(this).val();
  33.    document.cookie=\"profile_limit_". self::$formName ."_per_page = \" + value_selected;
  34.    __adianti_load_page(\"index.php?class=" . __CLASS__ . "&method=onReload\"); /* url para voltar*/
  35. });
  36.  
  37.        ");
  38.  
  39. /*
  40.   Na onReload, cola em substituição a linha com LIMIT
  41. */
  42.     $limit = GeneralFunctions::checkCookieForLimit('profile_limit_'. self::$formName .'_per_page');
  43.  
  44. /*
  45.   Coloca a função na sua helper de funções gerais
  46. */
  47.  
  48.  
  49.     public static function checkCookieForLimit($cookie_name)
  50.     {
  51.         // if ($cookie_name == 'profile_limit_vendas_per_page') {
  52.  
  53.             if(isset($_COOKIE[ $cookie_name ])){
  54.  
  55.                 $limit_l = $_COOKIE[ $cookie_name ];;
  56.                 if (!is_numeric($limit_l) || $limit_l == 0 ) {
  57.                     $limit = 10;
  58.                 } else {
  59.                     $limit = (int) $limit_l;
  60.                 }
  61.             } else {
  62.                 $limit = 10;
  63.             }
  64.  
  65.             $result = $limit;
  66.  
  67.         // }
  68.  
  69.         return $result;
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment