How to change default font size for ag-grid row cells in react js? - ag-grid-react

I am using ag-grid table for first time. I am not able to change the default font size of row cells(Not header portion). I want to change the font size of row cells(row data). I am using ag-theme-alpine.
Here is the code which I am using.
import React, { Component } from 'react';
import { render } from 'react-dom';
import { AgGridReact } from 'ag-grid-react';
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';
class App extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: [
{headerName: 'Make', field: 'make'},
{headerName: 'Model', field: 'model'},
{headerName: 'Price', field: 'price'}
],
rowData: [
{make: 'Toyota', model: 'Celica', price: 35000},
{make: 'Ford', model: 'Mondeo', price: 32000},
{make: 'Porsche', model: 'Boxter', price: 72000}
]
}
}
render() {
return (
<div
className="ag-theme-alpine"
style={{ height: '500px', width: '100%',fontSize:'20px' }}
>
<AgGridReact
columnDefs={this.state.columnDefs}
rowData={this.state.rowData}>
</AgGridReact>
</div>
);
}
}
render(<App />, document.getElementById('root'));
Please suggest a good solution.

You can do this in the ColDef by setting the cellStyle property in ColDef. You can set the font size as follows
columnDefs: [
{
headerName: 'Make',
field: 'make',
cellStyle: {fontSize: '11px'}
}
]

You can override the font size via CSS. Ag-Grid's CSS sets the font at the row level, and unfortunately it has an !important tag. Providing a higher selector specificity should do the trick:
div.ag-theme-alpine div.ag-row {
font-size: 12px !important;
}

You can set font-size and other parameters globally by customizing a theme: React Data Grid: Customising Themes
Define the style parameters in the styles.scss file like this:
.ag-theme-alpine {
#include ag-theme-alpine((
font-size: 10px,
));
}

Related

Invariant violation text strings must be rendered within a <Text> component

I am new to react-native development.
Whenever I try to use any framework I am getting error
Invariant violation text strings must be rendered within a Text
component
I tried two libs react-number-format and for pichart react-minimal-pie-chart
I know there are many questions already asked and I tried all but all are about syntax issue so I had to ask as I think it's not related to syntax as there is no any white space in code.
code as per below:
import React, { Component } from 'react';
import { View } from 'react-native';
import NumberFormat from "react-number-format"
import PieChart from react-minimal-pie-chart
export default class Calculation extends Component {
constructor(props) {
super(props);
this.state = {
};
render() {
return (
<View>
<View style={{ backgroundColor: "lightgray", height: 1, marginHorizontal: 5 }} />
<NumberFormat displayType="text" thousandSeparator={true} thousandsGroupStyle="lakh" prefix={'₹'} value={123456789} />
<PieChart
data={[
{ title: 'One', value: 10, color: '#E38627' },
{ title: 'Two', value: 15, color: '#C13C37' },
{ title: 'Three', value: 20, color: '#6A2135' },
]}
/>
</View>
);
}
}
react-native version is "0.60.5".
For reference I've attached screenshot.
Thanks in advance!!!
Okay ... So upon seeing your code i didn't see anything wrong with it. So I went and checked the source code of the two of the libraries that you have used.
Both the libraries that you have used are not compatible with react-native as they are made for react js that is for browser as they use dom elements like <div> and <input />
Like take react-number-format for example the main number_format.js from src returns
return (
<input
{...inputProps}
ref = {getInputRef}
/>
)
So, unfortunately you can't use these libraries for react-native.
This error arise when you write a text out of text scope. Text can be written only in text tags. The library which you have used might not be compatible and might render text outside the scope which is causing this issue.

Display image in ag-grid

ag-grid community v20, Angular 7.
I have a working ag-grid in my Angular 7 app. I want to display an image in a column. The https address is contained in the columns field. I've searched ag-grid's documentation and the web and have not found an example of this basic scenario. Can someone give a code example for the columnDef. Is cellRenderer the way to do this?
{ headerName: 'Select', field: 'Image', width: 75, sortable: false,
cellRenderer: '<span><img border="0" width = "15" height="10" src=xxxx ></span>' },
It is a multi-step process.
See Learn to customize Angular grid in less than 10 minutes
Create a custom component. 'ImageFormatterComponent.ts'
import { Component } from "#angular/core";
#Component({
selector: 'app-image-formatter-cell',
template: `<img border="0" width="50" height="50" src=\"{{ params.value }}\">` })
export class ImageFormatterComponent {
params: any;
agInit(params: any){
this.params = params;
}
}
Register in the app.module.ts
import { ImageFormatterComponent } from "./album/ImageFormatterComponent";
#NgModule({
declarations: [ImageFormatterComponent],
imports: [
AgGridModule.withComponents([ImageFormatterComponent])
],
In the component you are using it in:
import { ImageFormatterComponent } from "./ImageFormatterComponent";
columnDefs = [
{ headerName: 'Select',
field: 'Image',
width: 60,
sortable: false,
autoHeight: true,
cellRendererFramework: ImageFormatterComponent
}

Styling ionic 2 toast

Is there any way to style the text message within an ionic 2 toast?
I have tried this:
let toast = Toast.create({
message: "Some text on one line. <br /><br /> Some text on another line.",
duration: 15000,
showCloseButton: true,
closeButtonText: 'Got it!',
dismissOnPageChange: true
});
toast.onDismiss(() => {
console.log('Dismissed toast');
});
this.nav.present(toast);
}
But clearly you can't use html in the text so I am guessing the answer to my question is no?
You must add 'cssClass: "yourCssClassName"' in your toastCtrl function.
let toast = Toast.create({
message: "Some text on one line. <br /><br /> Some text on another line.",
duration: 15000,
showCloseButton: true,
closeButtonText: 'Got it!',
dismissOnPageChange: true,
cssClass: "yourCssClassName",
});
than you can add any feature to the your css class. But your css feature went outside the default page'css. Exmp:
page-your.page.scss.name {
//bla bla
}
.yourCssClassName {
text-align:center;
}
I was able to achieve a toaster color change by adding a custom class on the toaster create
let toast = this.toastCtrl.create({
message: 'Foobar was successfully added.',
duration: 5000,
cssClass: "toast-success"
});
toast.present();
}
In that pages scss file i then went outside the default nested page name ( because the toaster is NOT inside the root of ion page name thing). And all though this is a bit hacky i just explicitly targeted the next div element after the custom class that i added
.toast-success {
> div{
background-color:#32db64!important;
}
}
I say its hacky because you have to use the !important on it. You can avoid the !important by wrapping the .toast-success with .md,.ios,.wp{...
You can override the style default by overriding the main toaster variables in the theme/variables.scss file.
$toast-ios-background:(#32db64);
$toast-md-background:(#32db64);
$toast-wp-background:(#32db64);
This will only override the default value though and not a custom value. there are a few more variables that can be styled as well.
First, import toast controller from ionic-angular and make object of that in constructor.
import { ToastController } from "ionic-angular";
constructor(private _tc: ToastController) {
}
After that wherever you want to show your toast message write that.
let options = {
message: "Your toast message show here",
duration: 3000,
cssClass: "toast.scss"
};
this._tc.create(options).present();
Here is my scss:
.toast-message {
text-align: center;
}
Or you can check best example from this link. I think it will help you. :)
Or else check the answer on this link.
If you define your own css class in app.scss (not in page.scss)
you can style it with .toast-wrapper and .toast.message
No need to use > div{
Example:
.yourtoastclass {
.toast-wrapper {
background: blue;
opacity: 0.8;
border-radius: 5px;
text-align: center;
}
.toast-message {
font-size: 3.0rem;
color: white;
}
}
in theme/variables.scss you can make a default
Example (red and little transparent):
$toast-width: 75%; /* default 100% */
$toast-ios-background: rgba(153, 0, 0, .8);
$toast-md-background: rgba(153, 0, 0, 0.8);
Ionic 2 provide a very useful way to override their component style you can override the toaster SASS variable in src/theme/variables.scss by adding
$toast-ios-title-color: #f00 ;
$toast-md-title-color:#f00;
this will override the default style please refer to this Overriding Ionic Sass variable
You can accomplish, however you need to modify the toast component template itself.
Via explorer:
\node_modules\ionic-angular\components\toast\toast.js
Change line 194 (template):
{{d.message}} to <div [innerHTML]='d.message'></div>
You should be able to change any of the message styling in the css using .toast-message selector:
.toast-message {
font-family: Helvetica,
color: red
}
Or, if you look at the docs (http://ionicframework.com/docs/v2/api/components/toast/Toast/) there is a cssClass property you can use to assign your toast a specific class and then style that.
Change toast background color and opacity:
let toast = this.toastCtrl.create({
message: msg,
duration: 3000,
position: 'bottom',
cssClass: 'changeToast'
});
and add app.scss:
.changeToast{.toast-wrapper {opacity: 0.6; border-radius: 5px !important; text-align: center; background: color($colors, primary);}};
It's used with .toast-message
I tried all above, still didn't work, therefore I come across a new solution, you need cssClass outside of page css declaration:
let toast = this.toastCtrl.create({
message: msg,
duration: 3000,
position: 'bottom',
cssClass: 'toastcolor'
});
post-list.scss like this
page-post-list {
}
.toastcolor .toast-message {
background-color:skyblue;
}
Not sure about old Ionic versions, but in Ionic 5 you can't directly change inner CSS since it's encapsulated in the shadow
<ion-select>
#shadow-root
<div class="toast-container" part="container">
...
</div>
</ion-select>
so, to change .toast-container (for example) in your cssClass you should use:
.my-custom-class::part(container) {
flex-direction: column;
}
.my-custom-class {
.toast-container {
flex-direction: column; // will not work
}
}
I'm using ionic v5 with angular and
according to: https://ionicframework.com/docs/api/toast#css-shadow-parts
you can do something like this:
::ng-deep{
ion-toast::part(container) {
...
}
ion-toast::part(message) {
...
}
}

How do I get neon-animation to work in Polymer Dart 1.0

I have neon-animated-pages working with limited success. I can get it to animate using it's attributes entry-animation and exit-animation. This is great, but I've only been able to get it running with one animation routine for entry and one for exit like so
<neon-animated-pages class="waterfront" selected="{{ selected }}"
entry-animation="slide-down-animation"
exit-animation="slide-right-animation"
>
....
</neon-animated-pages>
and have the selected variable change to enact the animation.
I noticed all the tutorials for the JavaScript version, uses a behaviour to create a element which allows for sophisticated animations. So I use the Polymer Dart mixin equivalents
#HtmlImport('animated_picture.html')
library wellington.elements.animated_picture;
import 'package:polymer/polymer.dart';
import 'package:web_components/web_components.dart';
import 'package:polymer_elements/neon_animation_runner_behavior.dart';
import 'package:polymer_elements/neon_shared_element_animatable_behavior.dart';
import 'package:polymer_elements/neon_animation/animations/fade_in_animation.dart';
import 'package:polymer_elements/neon_animation/animations/fade_out_animation.dart';
import 'package:polymer_elements/neon_animation/animations/transform_animation.dart';
import 'package:polymer_elements/neon_animation/animations/slide_from_left_animation.dart';
import 'package:polymer_elements/neon_animation/animations/slide_left_animation.dart';
#PolymerRegister('animated-picture')
class AnimatedPicture extends PolymerElement with
NeonAnimationRunnerBehavior,
NeonSharedElementAnimatableBehavior {
String _src;
#Property(reflectToAttribute: true, notify: true)
String get src => _src;
#reflectable
void set src(val) {
_src = val;
notifyPath('src', src);
}
String _alt;
#Property(reflectToAttribute: true, notify: true)
String get alt => _alt;
#reflectable
void set alt(val) {
_alt = val;
notifyPath('alt', alt);
}
#Property(reflectToAttribute: true, notify: true)
Map get animationConfig => {
'value': () => {
'entry': [{
'name': 'slide-from-left',
'node': this
},
{
'name': 'transform-animation',
'node': this,
'transformAnimation': 'translateX(-100vh)'
}],
'exit': [{
'name': 'fade-out-animation',
'node': this
}]
}
};
AnimatedPicture.created() : super.created();
}
and the template
<dom-module id="animated-picture">
<style>
:host {
display: block;
}
.picture {
width: 1000px;
height: auto;
}
</style>
<template>
<picture id="container">
<source srcset="[[src]]">
<img class="picture" src="[[src]]" alt="[[alt]]">
</picture>
</template>
<script type="application/dart" src="animated_picture.dart"></script>
</dom-module>
From what I've seen, if this had been JavaScript, this would have worked, but no matter what I try I can't get this to work. I would put this element inside a neon-animated-pages element, as they do in the JavaScript demos, and nothing would happen, except the animated-picture visibility would change, with no animation when it was selected by neon-animated-pages, just like it would with a plain iron-pages selector. How do I do the equivalent with Polymer Dart 1.0?
I have answered my own question, on a hunch.
It was the values of animationConfig. My problem was I assumed the values for this would be the same as the JavaScript version, it's not. In the JavaScript version of this element, animationConfig is put in the properties part of the Polymer definition for the element.
...
properties: {
animationConfig: {
value: function() {
return {
'entry': {
...
},
'exit': {
...
}
}
}
}
},
...
You don't need the value part, and never do you need to return a function, in the Dart version. The Dart version is just a Map with 'entry' and 'exit' keys, which return lists of Maps, with the animation details in them, like so
#Property(reflectToAttribute: true, notify: true)
Map get animationConfig => {
'entry': [
{
'name': 'fade-in-animation',
'node': this,
'timing': {'delay': 500, 'duration': 1000}
},
{
'name': 'scale-up-animation',
'node': this,
'timing': {'duration': 2000}
}],
'exit': [{
'name': 'slide-left-animation',
'node': this
},
{
'name': 'fade-out-animation',
'node': this
}]
};
With of course the appropriate imports. For completeness I'm including the entire Polymer Dart element definition below. This works with <neon-animated-pages>, not as a standalone, you'll need to mixin the NeonAnimationRunnerBehavior, and call it's mixed in playAnimation, for it to work independently.
The Dart code
#HtmlImport('animated_picture.html')
library wellington.elements.animated_picture;
import 'package:polymer/polymer.dart';
import 'package:web_components/web_components.dart';
import 'package:polymer_elements/neon_animatable_behavior.dart';
import 'package:polymer_elements/neon_animation/animations/fade_in_animation.dart';
import 'package:polymer_elements/neon_animation/animations/scale_up_animation.dart';
import 'package:polymer_elements/neon_animation/animations/fade_out_animation.dart';
import 'package:polymer_elements/neon_animation/animations/slide_left_animation.dart';
#PolymerRegister('animated-picture')
class AnimatedPicture extends PolymerElement with
NeonAnimatableBehavior {
String _src;
#Property(reflectToAttribute: true, notify: true)
String get src => _src;
#reflectable
void set src(val) {
_src = val;
notifyPath('src', src);
}
String _alt;
#Property(reflectToAttribute: true, notify: true)
String get alt => _alt;
#reflectable
void set alt(val) {
_alt = val;
notifyPath('alt', alt);
}
#property
Map get animationConfig => {
'entry': [
{
'name': 'fade-in-animation',
'node': this,
'timing': {'delay': 500, 'duration': 1000}
},
{
'name': 'scale-up-animation',
'node': this,
'timing': {'duration': 2000}
}],
'exit': [{
'name': 'slide-left-animation',
'node': this
},
{
'name': 'fade-out-animation',
'node': this
}]
};
AnimatedPicture.created() : super.created();
}
The template file
<dom-module id="animated-picture">
<style>
:host {
display: block;
}
.picture {
width: 1000px;
height: auto;
}
</style>
<template>
<picture id="container">
<source srcset="[[src]]">
<img class="picture" src="[[src]]" alt="[[alt]]">
</picture>
</template>
<script type="application/dart" src="animated_picture.dart"></script>
</dom-module>
Hope this is of use to someone

Components are not draggable in Angular2 for Dart when bind objects using ngFor

I've created a component which is a draggable element.
#Component(
selector: 'draggable-component',
styles: const ['.element-to-drag {background-color: yellow; border: 1px solid blue; height: 50px; width: 50px;}'],
template: '''
<div class="element-to-drag"
draggable="true"
(dragstart)="onDragStart(\$event)"
(dragend)="onDragEnd(\$event)">
</div>''')
class DraggableComponent {
void onDragStart(MouseEvent e) {
print('onDragStart');
}
void onDragEnd(MouseEvent e) {
print('onDragEnd');
}
}
When I use it as a single element it fires drag start event and COULD BE dragged to the drop zone.
When I create it using ngFor of primitives list (numbers) all elements fire drag start event and COULD BE dragged to the drop zone.
But when I create it using ngFor of objects list all elements fire drag start event but COULD NOT BE dragged to the drop zone (they are not dragged).
Here is an example:
#Component(
selector: 'my-app',
directives: const [DraggableComponent, NgFor],
styles: const ['.container {border: 1px solid red;; height: 100px; width: 100px;}'],
template: '''
<div>
<div class="container"></div>
<h3>Single</h3>
<draggable-component></draggable-component>
<h3>Primitives</h3>
<draggable-component *ngFor="#example of examplesPrimitives"></draggable-component>
<h3>Objects</h3>
<draggable-component *ngFor="#example of examples"></draggable-component>
</div>
''')
class AppComponent {
get examples => [
{"name": 1},
{"name": 2},
{"name": 3},
{"name": 4} ];
get examplesPrimitives => [ 1,2,3,4,5];
}
How can I make bindings of objects draggable?
It was Angular2 wit Dart bug. Angular2 with TypeScript works fine in the same case.
An issue was created in Angular repository:
https://github.com/angular/angular/issues/6975

Resources