Center a checkbox in a Kendo Grid Cell - css

I'm using a template in a kendo grid to create checkbox:
$("#grid").kendoGrid({
dataSource: {
data: products,
schema: {
model: {
fields: {
ProductName: { type: "string" },
UnitPrice: { type: "number" },
UnitsInStock: { type: "number" },
Discontinued: { type: "boolean" }
}
}
},
pageSize: 20
},
height: 550,
scrollable: true,
sortable: true,
pageable: {
input: true,
numeric: false
},
columns: [
{
field:'<div style="text-align: center"><input id="masterCheck" class="k-checkbox" type="checkbox" /><label class="k-checkbox-label" for="masterCheck"></label></div>',
template: '<div style="text-align: center"><input id="${ProductName}" type="checkbox" class="k-checkbox rowSelect"/><label class="k-checkbox-label" for="${ProductName}"></label></div>',
headerAttributes:{ style:"text-align:center"},
width: 38,
editable: false,
sortable: false // may want to make this sortable later. will need to build a custom sorter.
},
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "130px" },
{ field: "UnitsInStock", title: "Units In Stock", width: "130px" },
{ field: "Discontinued", width: "130px" }
]
});
});
Here's a dojo of the code: http://dojo.telerik.com/IVopi
You'll notice the checkbox is in not centered in the grid cell. How can I center the checkbox in the grid cell?

In the templates you can lose the DIV and just include the checkbox and label. Then use attributes and headerAttributes to give the cell and header cell class names:
{
field:'<input id="masterCheck" class="k-checkbox" type="checkbox" /><label class="k-checkbox-label" for="masterCheck"></label>',
template: '<input id="${ProductName}" type="checkbox" class="k-checkbox rowSelect"/><label class="k-checkbox-label" for="${ProductName}"></label>',
headerAttributes:{
"class": "checkbox-header-cell",
},
attributes: {
"class": "checkbox-cell",
},
width: 38,
editable: false,
sortable: false // may want to make this sortable later. will need to build a custom sorter.
},
Now use CSS with those class names to center the checkboxes:
<style>
.checkbox-cell {
text-align: center !important;
padding: 0 !important;
}
.checkbox-header-cell {
text-align: center !important;
padding: 0 !important;
}
.checkbox-header-cell .k-checkbox-label:before {
margin-top: -12px !important;
}
</style>
You can play around with the CSS to get exactly what you want...

The reason why the content of the cell isn't centered is that the cell itself, the <td> element, has padding.
You can either remove this padding by overriding the styling of the grid or by applying a negative margin value to the content of your cell template.
Replace the text-align: center style you entered in your template with margin: -8px and the checkbox will be better positioned.

Related

Remove chart.js canvas padding and margin

I am using chart.js to show a line chart in an Angular component. The code does not have any padding or margins added for the chart. I added styling to set the padding and margin to zero both in the create the chart in the .ts file and in the style sheets and nothing makes any difference. When I inspect the element in Chrome developer mode it does not show any padding or margins, so I think the styling is internal to chart.js. Below is a screenshot with the chart element highlighted in Chrome developer mode.
As you can see, there is a margin or border on the left, bottom and right of the chart canvas element, but strangely not at the top. The spacing between the Y-Axis labels and the left of the chart are especially bad when viewed on a mobile phone so I really need to remove it. I have spent hours setting every element I can think of to have 0 padding and 0 margins and trying different changes to the code and style sheets and searching through other articles on the Internet including Stackoverflow but none of them seem to answer this specific question.
I also tried adding box-sizing:border-box; to the div container containing the chart but it did not make any difference, i.e. as suggested in this article:
Why is chart.js canvas not respecting the padding of the container element?
Here is my chart configuration:
this.myChart = new Chart("chartCanvas", {
type: 'line',
data: {
labels: labelVars,
datasets: datasets
},
options: {
elements: {
point: {
radius: 0
},
},
responsive: true,
maintainAspectRatio: false,
tooltips: {
mode: 'index',
intersect: false,
enabled: width > 640
},
hover: {
mode: 'nearest',
intersect: true
},
legend: {
display: false,
position: 'bottom',
labels: {
}
},
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'week',
tooltipFormat: 'MM/DD/YYYY'
},
display: true,
scaleLabel: {
display: true,
labelString: ''
},
ticks: {
autoSkip: true,
padding: 0,
maxTicksLimit: this.getTickLimit(),
maxRotation: this.getRotation(),
minRotation: this.getRotation()
},
gridLines: {
display: false,
offsetGridLines: true
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: ''
},
ticks: {
maxTicksLimit: 6,
beginAtZero: false
}
}]
}
}
});
Here is the current html:
<div class="chartContainer">
<canvas *ngIf="displayChart" id="chartCanvas"></canvas>
</div>
And here is the current css:
#chartCanvas {
padding-left: 0;
margin-left: 0;
}
.chartContainer {
height: 500px;
margin: 0;
padding: 0;
align-items: left;
align-self: left;
align-content: left;
}
Has anyone else encountered this problem?
I found the problem. I had the scaleLabel turned on but was not showing a scale label, which was adding extra space. I changed scaleLabel display to false as shown below and the space went away:
yAxes: [{
display: true,
scaleLabel: {
display: false,
labelString: ''
},
Depending on your chartjs config, you just have to set the padding of the chart.js config.
Info: Offset's in the canvas cannot be altered with css, since the chart is "drawn" on it.
(details: in the documentation)
For a example:
const config = {
type: 'line',
data: data,
options: {
...
plugins: {
....
},
scales:{
x: {
ticks:{ padding:0 }
}
},
}
};

Ext Js show a text above a button element

We are trying to develop a progress bar in which we have to align a text on top of button. We tried using different layouts but its not coming. Can some suggest a way to do it using CSS if possible. Attaching the example here.
CSS should solve your problem, this is a bit hard-coded and won't work as a generic solution but you can start from here:
First let's create a panel with progress bars and a button between them:
Ext.create('Ext.panel.Panel', {
renderTo: document.body,
height: 100,
layout: {
type: 'hbox',
align: 'middle'
},
defaults: {
margin: 2
},
items: [{
xtype: 'progressbar',
style: {
borderRadius: '5px'
},
height: 10,
width: 200,
text: ' ',
value: 1
}, {
xtype: 'container',
cls: 'btnWrapper',
items: [{
xtype: 'button',
height: 30,
cls: 'fa fa-check',
style: {
color: 'white'
}
}]
}, {
xtype: 'progressbar',
style: {
borderRadius: '5px'
},
height: 10,
text: ' ',
width: 200
}]
});
And here is the CSS to take care of the rest:
<style>
.btnWrapper:before {
content: 'BASICS';
font-weight: bold;
position: absolute;
top: -20px;
left: -10px;
width: 100%;
color: orange;
text-align: center;
}
.btnWrapper .x-btn {
border-radius: 30px;
}
</style>
Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/21n5

Best way to style w2ui grid

I have been using w2ui grid for displaying information in a table. It has worked great, but I did not particularly like how the table looks. So I was looking to style it. Is there a way to style the table without directly editing the css for w2ui?
As mentionned by TheUknown, I believe that it is more convenient to simply write As mentionned by TheUknown, I believe that it is more convenient to simply write your css rules.
But you can also use the 'style' common property on many elements such as your grid, columns or records.
See this example :
jsfiddle link
$('#myGrid').w2grid({
name : 'myGrid',
columns: [
{ field: 'fname', caption: 'First Name', size: '30%', style : 'border: 1px solid blue' },
{ field: 'lname', caption: 'Last Name', size: '30%', style : 'font-weight: bold' },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'sdate', caption: 'Start Date', size: '120px' },
],
records: [
{ recid: 1, fname: 'John', lname: 'Doe', email: 'jdoe#gmail.com', sdate: '4/3/2012', style : 'border: 1px solid green' },
{ recid: 2, fname: 'Stuart', lname: 'Motzart', email: 'jdoe#gmail.com', sdate: '4/3/2012' },
{ recid: 3, fname: 'Jin', lname: 'Franson', email: 'jdoe#gmail.com', sdate: '4/3/2012' }
],
style : 'border: 1px solid red'
});
You can add class onRender event or onRefresh event. This apply for w2ui widgets: layout, grid, toolbar, sidebar, tabs, form.
$('#myGrid').w2grid({
name : 'myGrid',
columns: [
{ ... },
],
records: [
{ ... }
],
onRender: function(event) {
event.onComplete = function() {
$('[name="myGrid"]').addClass('grid-custom');
}
},
});
This is an old question, but still somewhat relevant since this library is still being used by a lot of people.
My solution to this was to create a separate stylesheet called "w2ui-overrides.css" and then override the classes that are defined in the supplied w2ui stylesheet.
For instance, the default border style for the sidebar context menu is
.w2ui-overlay > div {
border-radius: 4px;
position: relative;
border: 3px solid #777777;
}
But I didn't care for that, so I added this to my overrides css:
.w2ui-overlay > div {
border-radius: 2px;
border: 1px solid #777;
}
And so on, for all of the styles I wanted to change. I use the Chrome developer tools to find the class names and selectors that I need to override.

Kendo UI grid row filter move filter operator icon position

I have a grid with very small columns with row filter, which cause them to have very small text-box. so I used
field: "OrderID",
width: 100,
filterable: {
cell: {
inputWidth: 65
}
}
but when I define inputWidth to enlarge the text field the filter operator does not move over and in fact cover up the partial space of the text-box. Therefore, I was wondering if there is a way to move the filter operator over or preferably over to the title header, like the columnMenu filter icon. Any help would be greatly appreciated, thanks.
I took the following example from: http://demos.telerik.com/kendo-ui/grid/filter-row
and modified width and inputwidth of orderID
<div id="example">
<div id="grid"></div>
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read:"http://demos.telerik.com/kendo- ui/service/Northwind.svc/Orders"
},
schema: {
model: {
fields: {
OrderID: { type: "number" },
Freight: { type: "number" },
ShipName: { type: "string" },
OrderDate: { type: "date" },
ShipCity: { type: "string" }
}
}
},
pageSize: 20,
serverPaging: true,
serverFiltering: true,
},
height: 550,
filterable: {
mode: "row"
},
pageable: true,
columns:
[{
field: "OrderID",
width: 100,
filterable: {
cell: {
inputWidth: 65
}
}
},
{
field: "ShipName",
width: 500,
title: "Ship Name",
filterable: {
cell: {
operator: "contains"
}
}
},{
field: "Freight",
width: 255,
filterable: {
cell: {
operator: "gte"
}
}
},{
field: "OrderDate",
title: "Order Date",
format: "{0:MM/dd/yyyy}"
}]
});
});

Using icons with List items

I am using Sencha Touch 2.2.1 . I want to display list items with icons, for that I am using itemTpl config property of the list. The image is rendered as icon but the list item is not getting aligned properly- it appears starting from much below. I want the text to get started from the top- it must be aligned horizontally with the image. I also tried changing 'margin' property but it didn't seem to work.
Please find my code below:
Ext.define('BBraunSencha.view.ListPanel',{
extend: 'Ext.Panel',
xtype: 'listpanel',
config:{
layout:{
type: 'vbox',
align: 'stretch'
},
items:[
{
xtype: 'label',
html: '<div style="margin-left: 20px;">List one</div>'
},{
xtype: 'list',
flex: 1,
ui:'round',
scrollable: true,
data:[
{ name: 'item1', price:'2000',in_stock : 'no'},
{ name: 'item2', price: '3000',in_stock :'yes'}
],
itemTpl: '<img src="images/Tulips.jpg" style="height: 50px;width: 50px;display:inline-block;margin-right:50px;"/>{name}'
}
]
} });
What can be the other way to achieve it?
Add a class to your css, then use that class for your itemTpl:
CSS file:
.tulip-icon {
background-image: url(images/Tulips.jpg);
background-size: 50px 50px;
background-repeat: no-repeat;
padding-left: 50px;
}
JS Code:
itemTpl: '<div class="tulip-icon">{name}</div>'
Add css:
.list-image{
height:20px;
width:20px;
float: left;
}
in js file:
itemTpl:'<div><img src="images/Tulips.jpg" class="list-image">{name}</div>'

Resources