This is a migrated thread and some comments may be shown as answers.

Smaller fonts and spacing for Grid

8 Answers 874 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 16 Apr 2020, 12:02 PM

I'm using the Bootstrap 4 theme and have a page which uses several Grids.

Is there a simple css wrapper class I can use for one of the Grids on the page (I don't want to alter css that will affect all grids) to make it smaller and more compact than the others?

For example, if it were pure bootstrap, I would simply add the following classes to the table element:

<table class="table table-sm">

8 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 21 Apr 2020, 10:54 AM

Hello, Barry,

You could set the font-size for a specific grid by targeting it by id:

 #server.k-widget{
     font-size:0.8rem;
}
#server.k-grid td {
    padding:0.5rem 0.5rem;
}

https://dojo.telerik.com/@bubblemaster/OdicURas

There are other alternatives to provide these styles from the grid configuration via HtmlAttributes() as part of the columns definition.

Let me know what you think.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Barry
Top achievements
Rank 1
answered on 21 Apr 2020, 12:42 PM

Thanks Alex, that's a good idea. I suppose I could make it a class instead and then just add that class wherever I need it via HtmlAttributes() or with js on the DataBound event

0
Alex Hajigeorgieva
Telerik team
answered on 24 Apr 2020, 09:42 AM

Hello, Barry,

I believe that the column attributes are better if you have editing in the grid.

This is because the DataBound() even will not be triggered when the user cancels a row and the original template without the changes will be shown. So that would mean adding one more event handler - Cancel().

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Barry
Top achievements
Rank 1
answered on 24 Apr 2020, 12:09 PM

I have been trying to avoid the HtmlAttributes because I feel like it could add too much to the markup. I much prefer adding a css class to a parent element and using the stylesheet to drill down to individual elements if necessary.

The following approach (edited for brevity) is working quite well so far:

CSS:
.k-widget.k-grid-sm {
  font-size: 0.8rem;
}
.k-grid.k-grid-sm .k-button {
  font-size: 0.8rem;
}
.k-grid.k-grid-sm td {
  padding: 0.4rem;
}
.k-grid.k-grid-sm th {
  padding: 0.4rem;
}
.k-grid.k-grid-sm .k-command-cell > .k-button {
  margin-top: 0;
  margin-bottom: 0;
}

 

JS:

function myGrid_DataBound(e) { $(this.element[0]).addClass('k-grid-sm'); }

Grid:

<div id="exampleGrid"></div>
<script>
kendo.syncReady(function(){
    jQuery("#exampleGrid").kendoGrid({
        "dataBound":myGrid_DataBound
        ...
        });
});
</script>

 

(hope this is clear - I don't know how to format code in this forum, sorry!)

0
Alex Hajigeorgieva
Telerik team
answered on 28 Apr 2020, 02:52 PM

Hello, Barry,

You could avoid getting the jQuery element of the grid in the dataBound function as it is already available:

function myGrid_DataBound(e) { 
  this.element.addClass('k-grid-sm');
}

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Barry
Top achievements
Rank 1
answered on 28 Apr 2020, 02:57 PM

Of course! Thanks, I should have spotted that.

 

So... how do I format code like yours in a forum post? ;-)

0
Alex Hajigeorgieva
Telerik team
answered on 01 May 2020, 09:05 AM

Hello, Barry,

Sorry I missed the question about formatting.

  1. When you click reply, click on Formatting options. Press enter a couple of times so you can navigate out of the snippet when you are done and wish to go back to text.
  2. The formatting options have a paintbrush button, click that 
  3. Paste the code snippets, format and click OK

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Barry
Top achievements
Rank 1
answered on 01 May 2020, 09:57 AM
So easy! Thank you
Tags
Grid
Asked by
Barry
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Barry
Top achievements
Rank 1
Share this question
or