EasyUI Forum
April 27, 2024, 04:04:02 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Data Grid Pagination  (Read 9309 times)
jaimi
Full Member
***
Posts: 119


View Profile
« on: September 11, 2014, 05:20:22 AM »

Hello,

I want to create the Pagination accordingly to the privilege of the user who signed in to the website.
My idea was to extend the json data with a new element "privilege" with the related value.
For my understanding the standard  json array has "total" (the count of records) and "rows" (the records of the resultset).

Regarding on the privilege value the set of visible buttons at the pagination should change.
How can I get access to this new json element? Is this a feasible approach?
Any other ideas?

Within php I created the json array:
....
$TrailList = json_encode($try->ARRAY_TRY);
echo $TrailList;

Within javascript I created the datagrid:
$('#edgTrail').edatagrid({
  title : 'Trekking-Routen',
  iconCls:'icon-Trail',
  width:'100%', 
  height:'auto',

  columns:[[ 
   {field:'OLT50A001T_KEY',title:'TrailKey',width:080,sortable:'true',hidden:'true'},
...

How can I get access to additional json-objects?


Thanks for answering.
Jaimi
« Last Edit: September 11, 2014, 10:54:15 PM by jaimi » Logged
Kevin
Jr. Member
**
Posts: 52


View Profile Email
« Reply #1 on: September 15, 2014, 04:36:36 PM »

Maybe I don't fully understand your question but would it not be easy to just create this on the server side with PHP?

So for example, directly after you create the datagrid, you insert something like the following;
Code:
<?php
   
if ($privilege == 0) echo "$('#edgTrail').pagination({layout:['first','links','last']});";
   else if (
$privilege == 1) echo "$('#edgTrail').pagination({layout:['first','prev','links','next','last']});";
   else echo 
"$('#edgTrail').pagination({layout:['list','sep','first','prev','next','last','refresh','manual','links']});";
?>

Logged
jaimi
Full Member
***
Posts: 119


View Profile
« Reply #2 on: September 16, 2014, 02:52:35 AM »

Thanks Kevin for answering,

I am not that familiar with handling the jQuery-objects.
I created the datagrid completely by javascript. For that I have created the pagination like that
Code:
 var TrailPager = $('#edgTrail').edatagrid('getPager');	
 
 TrailPager.pagination({
  showPageList: false,
  showRefresh : false,
  displayMsg  : '{from} bis {to} von {total} Tabellen'
  ,buttons     :[
   {iconCls:'icon-add'   ,handler:function(){addTrail();}}
  ,{iconCls:'icon-edit'  ,handler:function(){editTrail();}}
  ,{iconCls:'icon-remove',handler:function(){removeTrail();}}
  ,{iconCls:'icon-save'  ,handler:function(){saveTrail();}}
  ,{iconCls:'icon-undo'  ,handler:function(){undoTrail();}}
  ]
 });//TrailPager

Now I would like to control the visibility of the buttons regarding on the privilege-value which in some way must sent by the server. When the datagrid code sends the data request via url to the server it gets the result-set via json back. For my model-structure it seems to me the best to use the additional json-object "privilege". But how?

here is the modified json-file:
Code:
TrailList => {"privilege":"1","total":"17","rows":[{"OLT50A001T_KEY":"10000002","TRY_YEAR":"1989","TRY_ROUTE":"Rheurdt (DE) - Grote Brogel (BE)"}]}
Logged
Kevin
Jr. Member
**
Posts: 52


View Profile Email
« Reply #3 on: September 16, 2014, 07:51:36 AM »

Here is another idea you could use. The onLoadSuccess event will return all parameters sent from the server. You could then set the button there. ie.
Code:
$('#edgTrail').datagrid({
   onLoadSuccess: function(params){
      var TrailPager = $('#edgTrail').edatagrid('getPager');

      if (params.privilege == 1) {
         TrailPager.pagination({
            showPageList: false,
            showRefresh : false,
            displayMsg  : '{from} bis {to} von {total} Tabellen',
            buttons     :[
               {iconCls:'icon-add'   ,handler:function(){addTrail();}}
               ,{iconCls:'icon-edit'  ,handler:function(){editTrail();}}
               ,{iconCls:'icon-remove',handler:function(){removeTrail();}}
               ,{iconCls:'icon-save'  ,handler:function(){saveTrail();}}
               ,{iconCls:'icon-undo'  ,handler:function(){undoTrail();}}
            ]
         });
      }
      else if (params.privilege == 2) {
          //as per your setup
      }
   }
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!