EasyUI Forum
April 28, 2024, 06:27:32 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: datagrid: font size  (Read 8537 times)
korenanzo
Guest
« on: July 24, 2018, 04:06:18 AM »

Hi all,

I'd like to set the font style of a datagrid programmaticlaly, and let the datagrid to set its measures up according to it.

in textboxes I can do it with something like

$(textbox).css('font-size', size)

but what about datagrid?

thanks,

RIc
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 24, 2018, 06:08:00 PM »

This is the extended method to change the styles for the datagrid.
Code:
$.extend($.fn.datagrid.methods, {
  setStyles: function(jq, style){
    return jq.each(function(){
      var cc = $(this).closest('div.datagrid-view');
      var id = cc.attr('id');
      if (!id){
        id = '_easyui_datagrid_view'+($.fn.window.defaults.zIndex++);
        cc.attr('id', id);
      }
      var selector = '.datagrid-cell,.datagrid-cell-group,.datagrid-header-rownumber,.datagrid-cell-rownumber,.datagrid-header .datagrid-cell span';
      selector = $.map(selector.split(','), function(se){
        return '#'+id+' '+se;
      }).join(',');
      var ss = ['<style type="text/css" dgstyle="true">'];
      ss.push(selector+'{');
      for(var key in style){
        var value = style[key];
        key = key.replace(/([A-Z])/,"-$1").toLowerCase();
        ss.push(key+':'+value+';');
      }
      ss.push('}');
      ss.push('</style>');
      $(ss.join('\n')).appendTo(cc);
      cc.children('style[dgstyle]:not(:last)').remove();
    })
  }
})

Usage example:
Code:
$('#dg').datagrid('setStyles', {
  fontSize: '12px'
});
Logged
korenanzo
Guest
« Reply #2 on: July 25, 2018, 01:59:30 AM »

thanks stworthy

this code anyway does not afect   the size of the rows:

if I set the fontsize smaller, the row height remains the same;

I have noticed that in easyui.css there is

.datagrid-row {
  height: 25px;
}

How to change it accordingly with the new font size?



thanks,

RIc
« Last Edit: July 25, 2018, 03:14:25 AM by korenanzo » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: July 25, 2018, 05:31:52 AM »

Please look at this example http://code.reloado.com/asifoq4/2/edit#preview. The font size and row height can be modified at runtime.
Logged
korenanzo
Guest
« Reply #4 on: July 25, 2018, 05:49:15 AM »

thanks!
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!