EasyUI Forum
May 17, 2024, 10:54:29 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: How to declare alignment in a toolbar declared as array  (Read 7910 times)
Juan Antonio Martínez
Jr. Member
**
Posts: 68



View Profile
« on: July 18, 2014, 02:39:52 AM »

Hi all.
This is my first post to this forum. I've not found notices on propper use, so apologizes if this is not the correct way to ask for help

I have an on-the-fly declared datagrid, and so, toolbar is declared as an array.
Is there any way to specify some of the buttons are left-aligned and some other with right alignment

As HTML code It's easy to do:
Code:
    
    <!-- BARRA DE TAREAS DE LA TABLA DE PRUEBAS-->
    <div id="pruebas-toolbar" style="padding:5px 5px 25px 5px;">
        <span style="float:left;">
            <a id="pruebas-newBtn" href="#" class="easyui-linkbutton" onclick="newPrueba()">New prueba</a>
            <a id="pruebas-editBtn" href="#" class="easyui-linkbutton" onclick="editPrueba()">Edit prueba</a>
            <a id="pruebas-delBtn" href="#" class="easyui-linkbutton" onclick="deletePrueba()">Delete prueba</a>
        </span>
        <span style="float:right;">
                <a id="pruebas-reloadBtn" href="#" class="easyui-linkbutton" onclick="reloadDatagrid() >Actualizar</a>
        </span>
    </div>
    ....
   $('#pruebas-datagrid').datagrid({
   ...
   toolbar: '#pruebas-toolbar',
   ...
But don't know how to do it if declared as an array:
Code:
toolbar:  [
                {
                        id: 'pruebas-newBtn',
                        text: 'New prueba',
                        plain: true,
                        iconCls: 'icon-new',
                        handler: function(){newPrueba();}
                 },{
                        id: 'pruebas-editBtn',
                        text: 'Edit prueba',
                        plain: true,
                        iconCls: 'icon-edit',
                        handler: function(){editPrueba();}
                 },{
                        id: 'pruebas-delBtn',
                        text: 'Delete prueba',
                        plain: true,
                        iconCls: 'icon-delete',
                        handler: function(){deletePrueba();}
                 },{
                        id: 'prueba-reloadBtn',
                        text: 'Actualizar',
                        plain: true,
                        iconCls: 'icon-reload',
                        style: 'align:right', <<<<<<< How to tell toolbar that this item must be right aligned in toolbar?
                        handler: function(){reloadDatagrid();}    // reload the pruebas data}
                 }
               ],

Perhaps declare an string var like first code and assigning to 'toolbar' property? An easy example on how to do this?.

Thanks in advance
Juan Antonio
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 18, 2014, 06:20:03 PM »

Please extend a new method 'buildToolbar' to build tools with 'align' property.
Code:
$.extend($.fn.datagrid.methods, {
  buildToolbar: function(jq, items){
    return jq.each(function(){
      var p = $(this).datagrid('getPanel');
      p.children('div.datagrid-toolbar').remove();
      var tb = $('<div class="datagrid-toolbar"></div>').prependTo(p);
      $.map(items, function(item){
        var t = $('<a href="javascript:void(0)"></a>').appendTo(tb);
        t.linkbutton($.extend({}, item, {
          onClick:function(){
            if (item.handler){
              item.handler.call(this);
            }
            if (item.onClick){
              item.onClick.call(this);             
            }
          }
        }));
        t.css('float', item.align || '');
      })
    })
  }
});

Usage example:
Code:
  var items = [
  {
    id: 'pruebas-newBtn',
    text: 'New prueba',
    plain: true,
    iconCls: 'icon-new',
    onClick:function(){console.log('cc')},
    handler: function(){newPrueba();}
  },{
    id: 'pruebas-editBtn',
    text: 'Edit prueba',
    plain: true,
    iconCls: 'icon-edit',
    handler: function(){editPrueba();}
  },{
    id: 'pruebas-delBtn',
    text: 'Delete prueba',
    plain: true,
    iconCls: 'icon-delete',
    handler: function(){deletePrueba();}
  },{
    id: 'prueba-reloadBtn',
    text: 'Actualizar',
    plain: true,
    iconCls: 'icon-reload',
    align: 'right', // How to tell toolbar that this item must be right aligned in toolbar?
    handler: function(){reloadDatagrid();}    // reload the pruebas data}
  }];

  $('#dg').datagrid('buildToolbar', items)
Logged
Juan Antonio Martínez
Jr. Member
**
Posts: 68



View Profile
« Reply #2 on: July 21, 2014, 12:06:54 AM »

Works, great! Thanks a lot.

Cheers
Juan Antonio
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!