Angular Kendo Grid - javascript

I use Kendo UI for Angular. In the kendo grid I have a problem:
When I add a new record in the grid show 'valueField' instead textField.
How can I change that and set editable mode when new record appears not when click?
myCode:
<kendo-grid [data]="gridData" [loading]="loading" [navigable]="true"
(cellClick)="cellClickHandler($event)" (cellClose)="cellCloseHandler($event)" [height]="300"
(save)="addAddressRecord($event)" (remove)="removeAddressRecord($event)">
<kendo-grid-column field="isPrimary" editor="boolean" title="اصلی" width="50px">
</kendo-grid-column>
<kendo-grid-column field="title" title="عنوان"></kendo-grid-column>
<kendo-grid-column field="geographicalRegionId" title="منطقه جغرافیایی">
<ng-template kendoGridEditTemplate let-dataItem="dataItem" let-column="column"
let-formGroup="formGroup">
<kendo-combobox (filterChange)="filterGeographicalRegion($event)" [filterable]="true"
[data]="geographicalRegionId" textField="title" valueField="id"
[valuePrimitive]="true" [formControl]="formGroup.get('geographicalRegionId')">
</kendo-combobox>
</ng-template>
</kendo-grid-column>
<kendo-grid-column field="addressString" title="آدرس">
</kendo-grid-column>
<kendo-grid-column field="postalCode" title="کد پستی">
<ng-template kendoGridEditTemplate let-dataItem="dataItem" let-column="column"
let-formGroup="formGroup">
<input kendoTextBox [formControl]="formGroup.get('postalCode')"
(input)="($event)" />
</ng-template>
</kendo-grid-column>
<kendo-grid-column field="phone" title="تلفن">
</kendo-grid-column>
<kendo-grid-column field="fax" title="فاکس">
</kendo-grid-column>
<kendo-grid-column field="email" title="ایمیل">
</kendo-grid-column>
<kendo-grid-column width="50px">
<ng-template kendoGridCellTemplate let-isNew="isNew">
<button kendoGridRemoveCommand [icon]="'minus-outline'"></button>
<button kendoGridSaveCommand [icon]="'plus-outline'"></button>
</ng-template>
</kendo-grid-column>
</kendo-grid>

plz try this
create a component for dropdown
in HTML
<div [formGroup]='formGroup'>
<button #anchor (click)="toggle()" class="k-button btn-dropdown">{{ selectedKeys }}</button>
<kendo-popup [anchor]="anchor" (anchorViewportLeave)="show = false" class="popup" *ngIf="show">
<kendo-treeview
#tree
class="dropdown-kendo-treeview"
[nodes]="treeData | async"
textField="name"
kendoTreeViewExpandable
kendoTreeViewSelectable
kendoTreeViewHierarchyBinding
[hasChildren]="hasChildren"
[children]="fetchChildren"
[selectBy]="'name'"
[(selectedKeys)]="selectedKeys"
(selectionChange)="handleSelection($event)"
>
</kendo-treeview>
<div #dropdownIconDiv class="dropdown-icon-div">
<button class="m-1 dropdown-icon" kendoButton title="دریافت اطلاع از تغییرات" (click)="refresh()">
<i class="fas fa-redo"></i>
</button>
<button class="m-1 dropdown-icon" title="افزودن موقعیت جدید" (click)="newGeo()" kendoButton>
<i class="fas fa-plus"></i>
</button>
</div>
</kendo-popup>
<input #input kendoTextBox hidden [formControl]="name"/>
In ts file
#Input() name: FormControl;
#Input() formGroup: FormGroup;
#Input() selectedKeys = ['انتخاب ...'];
#ViewChild('anchor', {static: false}) anchor: ElementRef;
#ViewChild('dropdownIconDiv', {static: false, read: ElementRef}) dropdownIconDiv: ElementRef;
#ViewChild('tree', {static: false, read: ElementRef}) tree: ElementRef;
#ViewChild('input', {static: false}) input: ElementRef;
treeData: Observable<any[]>;
show = false;
#HostListener('keydown', ['$event'])
keydown(event: any): void {
if (event.keyCode === 27) {
this.toggle(false);
}
}
#HostListener('document:click', ['$event'])
documentClick(event: any): void {
if (!this.contains(event.target)) {
this.toggle(false);
}
}
constructor(
private geolocationService: GeolocationService,
private notificationService: NotificationService,
private tabService: TabService
) {
}
ngOnInit() {
this.getParentGeo();
this.getEditData();
}
getEditData(): void {
if (this.name.value) {
this.geolocationService.show(this.name.value).subscribe((response) => {
this.selectedKeys = [response.name];
},
(error) => this.errorHandler(error));
}
}
toggle(show?: boolean): void {
this.show = show !== undefined ? show : !this.show;
}
contains(target: any): boolean {
return this.anchor.nativeElement.contains(target) ||
(this.tree ? this.tree.nativeElement.contains(target) : false) ||
(this.dropdownIconDiv ? this.dropdownIconDiv.nativeElement.contains(target) : false);
}
handleSelection(e): void {
this.name.setValue(e.dataItem.id);
this.show = false;
}
newGeo() {
this.tabService.open(new Tab('معرفی موقعیت جغرافیایی', GeolocationComponent));
}
refresh() {
this.getParentGeo();
}
hasChildren() {
return true;
}
getParentGeo() {
this.treeData = this.geolocationService.SubLocations(0);
}
fetchChildren = (item: any) => {
return this.geolocationService.SubLocations(item.id);
};
showAlert(text: string, type: any): void {
this.notificationService.show({
content: text,
animation: {type: 'fade', duration: 400},
position: {horizontal: 'center', vertical: 'top'},
type: {style: type, icon: true},
closable: false,
hideAfter: 3000
});
}
// {ErrorCode,Message}
errorHandler(error: any) {
this.showAlert(error.error.Message, 'error');
}
in scss file
.btn-dropdown {
width: 190px;
justify-content: left;
appearance: none;
background-image: linear-gradient(45deg, transparent 50%, #000 50%),
linear-gradient(135deg, #000 50%, transparent 50%) !important;
background-position: calc(10% - 0.78rem) 0.5rem, calc(10% - 0.5rem) 0.5rem;
background-size: 0.3rem 0.3rem, 0.3rem 0.3rem;
background-repeat: no-repeat;
}
.popup {
width: 190px;
}
.dropdown-kendo-treeview {
width: 190px !important;
height: 200px !important;
}
.dropdown-icon-div {
border-top: 1px solid #00000029;
height: 50px;
width: 100%;
text-align: left;
}
.dropdown-icon {
width: 30px;
height: 30px;
font-size: 16px;
margin: 10px 5px !important;
}
and usage in grid kendo
<ng-template kendoGridEditTemplate let-dataItem="dataItem" let-column="column"
let-formGroup="formGroup">
<zino-geolocation-tree-dropdown [formGroup]="formGroup" [selectedKeys]="selectedKeys"
[name]="formGroup.get('geographicalRegionId')"></zino-geolocation-tree-dropdown>
</ng-template>

Related

Showing dynamic text in spinner angular material

I have a spinner , but I also want some text in the spinner independent of the component. So for example if you are doing a save action, then the spinner will showing: ...saving. But for example if you do a search action. The spinner will showing: ..processing and so on.
I have this as spinner component:
<div *ngIf="(isLoading | async)" class="overlay">
<div>
<mat-progress-spinner class="spinner" [color]="color" [mode]="mode" [value]="value"> </mat-progress-spinner>
<div style="position:relative; top: -60px; left: 30px;">{{message}}</div>
</div>
</div>
and ts script:
export class LoaderComponent {
color = 'primary';
mode = 'indeterminate';
value = 50;
message = 'Hello there';
isLoading: Subject<boolean> = this.loaderService.loaderState;
constructor(private loaderService: LoaderService) {}
}
and then for example I load the spinner in this component: listComponent
<app-loader ></app-loader>
So I see the spinner but not the message.
So what I have to improve so that the text will also been shown?
And how to make the text dynamically? So that you can put any text message in it?
Thank you
I have it now like this:
<div *ngIf="(isLoading | async)" class="overlay">
<div>
<mat-progress-spinner class="spinner" [color]="color" [mode]="mode" [value]="value"> </mat-progress-spinner>
<div style="position:absolute; top: -60px; left: 30px;">{{message}}</div>
</div>
</div>
export class LoaderComponent {
color = 'primary';
mode = 'indeterminate';
value = 50;
#Input()
message = 'Hello there';
isLoading: Subject<boolean> = this.loaderService.loaderState;
constructor(private loaderService: LoaderService) {}
}
and this is the css:
.overlay {
position:fixed;
display:block;
width:100%;
height:100%;
top:0;
left:0;
background-color:rgba(74,74,74,.8);
z-index:99999;
}
.spinner {
margin:auto;
position:absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%);
}
You can find Working demo here in this StackBlitz Link
You have to use Behavior Subject and service...
Your app.component.html is..
<mat-toolbar color="primary">Spinner Demo</mat-toolbar>
<div style="margin:1em">
<button style="margin:1rem" mat-raised-button color="primary" (click)="spinner('search')">Search</button>
<button mat-raised-button color="primary" (click)="spinner('Send')">Send</button>
<button style="margin:1rem" mat-raised-button color="primary" (click)="spinner('Save')">Save</button>
</div>
<app-search-output ></app-search-output>
Your app.component.ts is...
export class AppComponent {
constructor( private serachService: SearchService){
}
spinner(term){
this.serachService.sendData(term);
}
ngOnInit(){
}
}
Your Service where you can use behaviorSubject as like this...
export class SearchService {
searchData$: BehaviorSubject<object[]> = new BehaviorSubject<object[]>([{}]);
constructor() { }
sendData(term){
this.searchData$.next(term)
}
getData(){
return this.searchData$.asObservable();
}
}
Your spinner component HTML is...
<div style="margin:2em auto; padding:1rem; box-shadow: 1px 2px 7px red; width:50vw">
<span style="margin:1em; padding:1rem">{{bookData$ |async |json}}</span>
<mat-spinner style="margin:1em" color="warn" ></mat-spinner>
</div>
Your spinner.component.ts is ...
export class SearchOutputComponent implements OnInit {
bookData$;
constructor(private searchService: SearchService) { }
ngOnInit() {
this.bookData$ = this.searchService.getData();
}
}
You can pass text values as #Input to your component and use the component as below
I believe you are not able to see it because of css issue. Try making the text position:absolute.
<div *ngIf="(isLoading | async)" class="overlay">
<div>
<mat-progress-spinner class="spinner" [color]="color" [mode]="mode" [value]="value"> </mat-progress-spinner>
<div style="position:absolute; top: -60px; left: 30px;">{{message}}</div>
</div>
</div>
To further debug please create a stackblitz.
<app-loader [message] = "Processing"></app-loader>
Spinner Component
import { Component, Input, OnInit } from '#angular/core';
export class LoaderComponent {
color = 'primary';
mode = 'indeterminate';
value = 50;
#Input()
message = 'Hello there'; // Default text will be Hello there but if you pass anything as stated above then it will be replaced.
isLoading: Subject<boolean> = this.loaderService.loaderState;
constructor(private loaderService: LoaderService) {}
}
Try to change style position to relative in your html file it should work:
HTML file
<div *ngIf="(isLoading | async)" class="overlay">
<div>
<mat-progress-spinner class="spinner" [color]="color" [mode]="mode" [value]="value"> </mat-progress-spinner>
<div style="position:relative; top: -60px; left: 30px;">{{message}}
</div>
</div>
</div>
TS file
export class ProgressSpinnerOverviewExample {
color = 'primary';
mode = 'indeterminate';
value = 50;
#Input()
message = 'Hello';
isLoading = true;
constructor() {}
}

Mat Paginator didn't show

Hi I am using angular to display a tabulate page, in this page i will display 100 records and implement pagination on the records
I used the example showing in the official documents, but didn't work. I am struggling for a while, so I am wondering if I can get help here:
here is the component I created for the page.
In the html page:
<div id="main-body">
<div class="search-bar">
<div class="input-group mb-3">
<select [(ngModel)]="searchBy" class="border-primary">
<option value="">-- choose an option--</option>
<option value="id"> ID</option>
<!-- <option value="anchorPoint">Anchor Point</option> -->
<option *ngFor="let label of homeLabelList" value="anchorPoint">{{label | uppercase}}</option>
</select>
<input type="text" class="form-control card border-primary ele fnt" placeholder="Enter the SIR ID or Host or sha256 or User ID"
aria-label="Ticket Id" aria-describedby="button-addon2" [(ngModel)]="currentTicketId">
<div class="input-group-append">
<button class="btn btn-primary ele" type="button" id="button-addon2" (click)="searchTicket()">Lets
Search!</button>
</div>
</div>
<div class="dates filter-tab">
<form [formGroup]="filterAllForm" (ngSubmit)="filterAllTicket()" class="table-list">
<mat-form-field class="filter-box">
<input matInput [matDatepicker]="startDate" placeholder="Choose a start date" formControlName="startDate" />
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
<mat-datepicker #startDate></mat-datepicker>
</mat-form-field>
<mat-form-field class="filter-box">
<input matInput [matDatepicker]="endDate" placeholder="Choose a end date" formControlName="endDate" />
<mat-datepicker-toggle matSuffix [for]="endDate"></mat-datepicker-toggle>
<mat-datepicker #endDate></mat-datepicker>
</mat-form-field>
<button class="btn btn-primary filter-button ele" id="button-addon4" type="submit"> Filter </button>
</form>
</div>
</div>
<div class="ticket-result">
<div *ngIf="allTickets" class="ticket-container">
<table mat-table [dataSource]="ticketList" class="mat-elevation-z8">
<!-- Ticket Column -->
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> SIR ID </th>
<td mat-cell *matCellDef="let element">
<a href='ticket/{{element.id}}'>{{element.id}}</a>
</td>
</ng-container>
<!-- Type Column event source -->
<ng-container matColumnDef="findingSourceSystem">
<th mat-header-cell *matHeaderCellDef> Source </th>
<td mat-cell *matCellDef="let element"> {{element.findingSourceSystem}} </td>
</ng-container>
<!-- Type Column Related Event count -->
<ng-container matColumnDef="label">
<th mat-header-cell *matHeaderCellDef> Related Cases </th>
<td mat-cell *matCellDef="let element"> {{element.relatedVertices.length}} </td>
</ng-container>
<!-- Type Column event source -->
<ng-container matColumnDef="caseStatus">
<th mat-header-cell *matHeaderCellDef> Case Status </th>
<td mat-cell *matCellDef="let element"> {{element.caseStatus}} </td>
</ng-container>
<!-- Type Column event source -->
<ng-container matColumnDef="caseCreateTimestamp">
<th mat-header-cell *matHeaderCellDef> Case Created </th>
<td mat-cell *matCellDef="let element"> {{element.caseCreateTimestamp | date:'MMM d, y, h:mm:ss a'}}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<mat-paginator [length]="100" [pageSize]="10" [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
</table>
</div>
</div>
</div>
In the scss file:
#main-body {
padding-top: 20px;
}
table {
width: 80%;
margin-left: 10%;
}
.search-bar {
margin-top: 20px;
margin-left: 10%;
margin-right: 10%;
position: fixed;
width: 80%;
background: white;
}
.ticket-result {
padding-top: 160px;
}
.filter-card {
margin-left: 10%;
margin-right: 10%;
}
#related-ticket{
margin-left: 10%;
margin-right: 10%;
}
.link {
color: blue;
cursor: pointer;
text-decoration: underline;
}
#button-addon4{
width: 8%
}
// input::placeholder{
// color: black;
// }
.fnt{
color: blue;
}
.json-data {
background: lightgrey;
height: 500px;
overflow: auto;
}
table#t01 {
width: 50%;
background-color: #f1f1c1;
border: 1px solid black;
border-collapse: collapse;
}
#thh, #tdd, #trr {
padding: 15px;
text-align: left;
border: 1px solid black;
}
.tab { margin-left: 110px; }
.filter-box {
width: 27%;
margin-right: 5px;
margin-left: 5px;
}
// .filter-button {
// background: #007bff!important;
// }
.ele {
margin-right: 10px;
}
.filter-tab {
margin: 2% 10%;
border: none;
}
.related-ticket-table {
margin: 2%;
}
.ticket-container {
height: 520px;
overflow: auto;
}
.dates{
margin-left: 25%;
}
.btn-primary{
background-color: #000099;
}
.border-primary{
color: #000099;
}
#button-addon4{
width: 15%
}
#iconSpan {
position : absolute;
top:1%;
left :14%;
}
ts code
import { Component, OnInit, ViewChild } from '#angular/core';
import {FormBuilder, FormControl, FormGroup} from '#angular/forms';
import {MatPaginator} from '#angular/material/paginator';
import { TicketService } from '../../services/ticket.service';
import { Ticket } from '../../models/ticket';
import { TicketDetail } from '../../models/ticket-detail';
import { TicketDetailComponent } from '../ticket-detail/ticket.detail.component';
import { query } from '#angular/animations';
#Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
ticketList: Ticket[] = [];
originalTicketList: Ticket[] = [];
displayedColumns = ['id', 'findingSourceSystem','label', 'caseStatus', 'caseCreateTimestamp'];
displayedDetailColumns = ['id', 'label', 'findingSourceSystem','caseCreateTimestamp'];
filterAllForm: FormGroup;
allTickets: boolean = true;
labelList: string[];
homeLabelList: string[];
currentTicketId: string;
searchBy: string = '';
#ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
constructor(private ticket: TicketService,
private formBuilder: FormBuilder) { }
ngOnInit() {
this.filterAllForm = this.formBuilder.group({
startDate: [''],
endDate: ['']
});
this.getAllLabels();
this.getAllTicket();
this.getAllUniqueLabels();
}
get filterFormControls() { return this.filterAllForm.controls; }
getAllTicket() {
this.allTickets = true;
let queryParams = '';
console.log(this.currentTicketId) + " " + this.searchBy;
if(this.searchBy === 'id') {
queryParams = 'id=' + this.currentTicketId;
} else if(this.searchBy === 'anchorPoint') {
queryParams = "anchor=" + this.currentTicketId;
}
this.ticket.getAllTicket(queryParams).subscribe((res: Ticket[]) => {
this.ticketList = res;
this.ticketList['paginator'] = this.paginator;
this.originalTicketList = this.ticketList;
});
}
filterAllTicket() {
let startFlag = this.filterAllForm.value.startDate != undefined && this.filterAllForm.value.startDate != "";
let endFlag = this.filterAllForm.value.endDate != undefined && this.filterAllForm.value.endDate != "";
if(startFlag || endFlag) {
let arrays = [];
for(let ticket of this.originalTicketList) {
let ticketStartDate = new Date(ticket.caseCreateTimestamp);
let flag = startFlag && ticketStartDate >= this.filterAllForm.value.startDate;
if(endFlag) {
flag = flag && ticketStartDate <= this.filterAllForm.value.endDate;
}
if(flag) {
arrays.push(ticket);
}
}
this.ticketList = arrays;
}
}
getAllLabels() {
this.ticket.getLabel().subscribe((res: string[]) => {
this.labelList = res;
this.labelList.push("all");
this.labelList.sort();
});
}
getAllUniqueLabels() {
this.ticket.getLabel().subscribe((res: string[]) => {
this.homeLabelList = res;
this.homeLabelList.sort();
});
}
searchTicket() {
this.getAllTicket();
}
}
Initially, I was wondering if the .ticket-container class in the css effected the pagination, I removed, the table going up when I srcolling down. Also, still didn't show pages. This is what I got now. You can see the table can be scrolled down but did't have pages.
You need to place it outside of <table> element as it doesn't have this child element specified.
Replace:
<mat-paginator [length]="100" [pageSize]="10" [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
</table>
With:
</table>
<mat-paginator [length]="100" [pageSize]="10" [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>

Angular Material stranger render behavior

I'm using the latest version of Angular and Angular Material. I'm having issues with my components. The page Load like this:
Before de click
And the content just appear when I click on the menu.
After clicking
I already tried to uninstall and install all the meterial stuff. And this issue continues. I have a separate module to import and export all the material components. Here is the code of the component that is using the material tags:
profile.component.ts
import { Component, OnInit } from '#angular/core';
import {AuthService} from "../../services/auth.service";
import {User} from "../../model/model.user";
import {Router} from "#angular/router";
import { Expense } from '../../model/model.expense';
import { ReceiptService } from "../../services/receipt.service";
import { ExpenseService } from './../../services/expense.service';
import { Receipt } from './../../model/model.receipt';
#Component({
selector: 'app-profile',
templateUrl: './profile.component.html',
styleUrls: ['./profile.component.css']
})
export class ProfileComponent implements OnInit {
totalReceita = 0;
totalDespesa = 0;
receipts = []
expenses = []
currentUser: User;
constructor(public authService: AuthService, public router: Router, public receiptService: ReceiptService, public expenseService: ExpenseService) {
this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
}
ngOnInit() {
this.receiptService.getReceipts(this.currentUser.id).subscribe(
data => {
console.log(data)
this.receipts = this.retiraArrayRec(data);
this.somaTudoRec();
}
);
this.expenseService.getExpenses(this.currentUser.id).subscribe(
data => {
this.expenses =this.retiraArrayDesp(data);
this.somaTudoDes();
}
);
console.log(this.receipts)
}
retiraArrayRec(data){
let lista = []
data.forEach(element => {
let receita : Receipt = new Receipt;
receita.name = element[0];
receita.value = element[1]
lista.push(receita);
});
return lista;
}
retiraArrayDesp(data){
let lista = []
data.forEach(element => {
let despesa : Expense = new Expense;
despesa.name = element[0];
despesa.value = element[1]
lista.push(despesa);
});
return lista;
}
somaTudoRec(){
this.receipts.forEach(element => {
this.totalReceita += element.value;
});
}
somaTudoDes(){
this.expenses.forEach(element => {
this.totalDespesa += element.value;
});
}
// login out from the app
logOut() {
this.authService.logOut()
.subscribe(
data => {
this.router.navigate(['/login']);
},
error => {
});
}
}
profile.component.html
<mat-sidenav-container fullscreen class="menu-container">
<mat-sidenav #sidenav>
<mat-nav-list>
<a mat-list-item routerLink="/home" routerLinkActive="active-list-item">
<h2 matLine>Home</h2>
<mat-icon matListIcon>home</mat-icon>
</a>
<a mat-list-item routerLink="/account" routerLinkActive="active-list-item">
<h2 matLine>Receitas</h2>
<mat-icon matListIcon>local_atm</mat-icon>
</a>
<a mat-list-item routerLink="/settings" routerLinkActive="active-list-item">
<h2 matLine>Despesas</h2>
<mat-icon matListIcon>show_chart</mat-icon>
</a>
<a mat-list-item routerLink="/settings" routerLinkActive="active-list-item">
<h2 matLine>Notificações</h2>
<mat-icon matListIcon>notification_important</mat-icon>
</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content fxFlexFill>
<mat-toolbar>
<button class="hamburger mat-button" mat-icon-button (click)="sidenav.toggle()">
<mat-icon>menu</mat-icon>
<span>Menu</span>
</button>
<span>Bem vindo ao CPF, Pedro</span>
<button mat-icon-button [mat-menu-trigger-for]="menu">
<mat-icon>more_vert</mat-icon>
</button>
</mat-toolbar>
<mat-menu x-position="before" #menu="matMenu">
<button mat-menu-item>
<mat-icon>person</mat-icon>
<span>Perfil</span>
</button>
<button mat-menu-item>
<mat-icon>money_off</mat-icon>
<span>Sair</span>
</button>
</mat-menu>
</mat-sidenav-content>
</mat-sidenav-container>
profile.component.css
mat-toolbar {
background-image: linear-gradient(to bottom, #00b4db, #0083b0);
color: #fff;
justify-content: space-between;
box-shadow: 0 2px 5px 0 rgba(0,0,0,.3);
}
span {
font-size: 16px;
font-weight: 700;
}
.hamburger {
height: 100%;
font-size: 18px;
}
.mat-sidenav-container {
min-width: 400px;
max-width: 100%;
}
.mat-sidenav {
flex: 0 1 auto;
}
.menu-spacer {
flex: 1;
}
.mat-list-item-content {
padding: 0 25px;
}
.menu-container {
min-width: 200px;
max-width: 100%;
}
First, please consider that you need to insert style into the project:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
If it did not solve the problem, I guess it's because you are using another font and also added !important for the font, please try to add the code below in your style.css (or style.scss) which is the general/public CSS file which effects on your whole project:
mat-icon{
font-family: 'Material Icons' !important;
}

ionic 2 : hide and display div with ngClass

I have a div on my ionic 2 page and I want to display and hide it when click , the first part is done (display) I use ngClass to do it but the second part can't do it I think is a logic problem , see the image bellow :
, here is the html code :
<ion-content>
<ion-fab right [ngClass]="isCalendar ? 'show-calendar':'hide-calendar' " (click)="showCalendar();">
<div class="close" (click)="hideCalendar()" [ngClass]="isNotCalendar ? 'hide-Calendar' :'show-calendar'">
<ion-icon class="icon-close" name="ios-close"></ion-icon>
</div>
<p class="day" [ngClass]="isClicked ? 'day-no-click':'day' ">DAY</p>
<p class="month" [ngClass]="isClicked ? 'monthclicked':'month' " (click)="selectMonth()">MONTH</p>
<p class="year">YEAR</p>
<div class="button-date" ion-button round>
<p>. . .</p>
</div>
<div class="Progress" style="transform: rotate(90deg);">
<progress max="100" value="0" class="Progress-main">
<div class="Progress-bar" role="presentation">
<span class="Progress-value" style="width: 80%;"></span>
</div>
</progress>
</div>
</ion-fab>
<ion-fab top left>
<ion-searchbar> </ion-searchbar>
</ion-fab>
<ion-img class="map" [src]="mapsource" (click)="changeView(mapsource)"></ion-img>
<ion-icon class="icon-bonfire" name="ios-bonfire"></ion-icon>
<ion-icon class="icon-heart" name="md-heart"></ion-icon>
<ion-icon class="icon-nuclear" name="md-nuclear"></ion-icon>
<ion-fab top right (click)="showCalendar()">
<button ion-fab color="whitecolor"><ion-icon class="calandaricon" name="md-calendar"></ion-icon></button>
</ion-fab>
<div class="calendar">
</div>
<ion-fab bottom right class="fablocate">
<button ion-fab color="whitecolor"><ion-icon class="locateicon" name="md-locate"></ion-icon></button>
</ion-fab>
<ion-fab (click)="ListParrots();" bottom left class="linklist">
<ion-img class="parrot-list-link" src="img/citydirty.jpg"></ion-img>
</ion-fab>
</ion-content>
and here is the ts file code :
import { Component } from '#angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ParrotListPage } from '../parrot-list/parrot-list';
/**
* Generated class for the MapPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
#IonicPage()
#Component({
selector: 'page-map',
templateUrl: 'map.html',
})
export class MapPage {
mapsource :any;
isClicked : Boolean= false;
isCalendar : Boolean=false;
isNotCalendar : Boolean=false;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.mapsource = '../../img/map.jpg';
}
changeView(mapsource){
this.mapsource ='../../img/mapzoom.jpg';
if (mapsource == this.mapsource) {
this.mapsource = '../../img/map.jpg';
}else{
this.mapsource= '../../img/mapzoom.jpg';
}
}
ionViewDidLoad() {
console.log('ionViewDidLoad MapPage');
}
ListParrots(){
this.navCtrl.push(ParrotListPage);
}
showCalendar(){
this.isCalendar = true;
}
hideCalendar(){
this.isNotCalendar = false;
}
selectMonth() {
this.isClicked = true;
}
}
and here is the css
.show-calendar {
height: 100%;
width: 25%;
background-color: color($colors, notification-blue);
margin-right: -10px;
z-index: 1000;
text-align: center;
}
.hide-calendar {
display: none;
}
.close {
width: 50px;
height: 50px;
text-align: center;
background-color: white;
border-radius: 50%;
line-height: 50px;
margin-top: 20px;
margin-left: auto;
margin-right: auto;
}
can some check with the logic and tell how to define exactly the ngClass functionalities?
Try like this :
<button class="btn btn-primary" (click)="showCalendar()">showCalendar</button>
<div [ngClass]="isCalendar ? 'show-calendar':'hide-calendar'">
<h1>Calendar Content</h1>
</div>
and method :
export class Component {
private isCalendar: boolean = false;
showCalendar() {
this.isCalendar = this.isCalendar ? false : true;
}
}

gridOption is not receiving my data from controller

I am new to angularjs and I am trying to populate a ui grid with data from a data base. I have tried searching for other issue sbut I haven't found anything similar to my issue online. The table shows just fine but none of my data is populating. I have seen it in the developer tools in Chrome under Source and it appears to be properly formated as a Json object but I cant get it to display anything in the table. I know it is probably something small I am doing or not doing any help would be appreciated.
Below is my controller js
var app = angular.module('skill', ["ui.grid",
"ui.grid.edit",
"ui.grid.selection",
"ui.grid.pagination",
"ui.grid.exporter",
"ui.grid.cellNav"]);
app.controller('SkillEntryController', function ($scope, $http, $interval, uiGridConstants, SkillService) {
$scope.data = [];
SkillService.GetSkills().then(function (d) {
$scope.data = d.data;
}, function () {
alert('Failed');
});
$scope.columns = [
{ name: "SkillName", displayName: "Skill Code", minWidth: 150, width: "33%" },
{ name: "Category", minWidth: 150, width: "33%" },
{ name: "Description", minWidth: 150, width: "33%" }
];
$scope.gridOptions = {
enableSorting: true,
enableRowSelection: true,
enableCellEditOnFocus: true,
exporterHeaderFilterUseName: true,
treeRowHeaderAlwaysVisible: false,
paginationPageSizes: [25, 50, 75],
paginationPageSize: 25,
columnDefs: $scope.columns,
data: $scope.data,
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
}
};
}).factory('SkillService', function ($http) {
var fac = {}
fac.GetSkills = function () {
return $http.get('/Skills/GetSkills');
}
return fac;
});
Here is my factory method:
public JsonResult GetSkills()
{
List<Skill> c = new List<Skill>();
return new JsonResult { Data = c.Select(x => new { x.Category, x.Description, x.SkillCodeID, x.SkillName }), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
And here is my cshtml file:
#model IEnumerable<SkillResourceCenterApp.Models.Skill>
#using Newtonsoft.Json;
#{
ViewData["Title"] = "Add Skill";
}
#section scripts{
<link href="~/Content/ui-grid.css" rel="stylesheet" />
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/ui-grid.js"></script>
<script src="~/Scripts/Controller/skill-entry-controller.js"></script>
}
<style>
.ui-grid-cell.cell-center {
text-align: center;
}
.ui-grid-cell.cell-right {
text-align: right;
}
.no-rows {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0.4);
}
.no-rows .msg {
opacity: 1;
position: absolute;
top: 30%;
left: 33%;
width: 30%;
height: 25%;
line-height: 200%;
background-color: #eee;
border-radius: 4px;
border: 1px solid #555;
text-align: center;
font-size: 24px;
display: table;
}
.no-rows .msg span {
display: table-cell;
vertical-align: middle;
}
</style>
<h3>#ViewData["Title"]</h3>
<p>
#Html.ActionLink("Create New", "Create")
</p>
<div class="container-fluid" ng-app="skill" ng-controller="SkillEntryController">
<div class="row">
<button type="button" ng-click="addNewRow()" class="btn btn-default col-sm-3 col-md-2">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add Row
</button>
<button type="button" ng-click="deleteSelected()" class="btn btn-default col-sm-3 col-md-2">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete Selected
</button>
<button type="button" ng-click="exportToCSV()" class="btn btn-default col-sm-3 col-md-2">
<span class="glyphicon glyphicon-download" aria-hidden="true"></span> Export to Excel
</button>
<button type="button" ng-click="save()" class="btn btn-primary col-md-offset-4 pull-right col-sm-2">
Save
</button>
</div>
<div class="row">
<div class="grid" ui-grid="gridOptions"
ui-grid-pagination
ui-grid-selection
ui-grid-edit
ui-grid-exporter
ui-grid-cellNav
style="height: 500px;">
<div class="no-rows" ng-show="!gridOptions.data.length">
<div class="msg">
<span>No Results</span>
</div>
</div>
</div>
</div>
</div>
You're missing the field definition in columnDefs. Have a look at https://github.com/angular-ui/ui-grid/wiki/Defining-columns
var columnDefs: [{
field: 'foo',
displayName: 'my foo',
visible: true,
maxWidth: 90,
enableColumnResizing: false,
cellTemplate: "<div>{{row.entity.foo}}</div>"
}];

Categories

Resources