I tried to set a responsive table with angular-datatables (for angular 7) and bootstrap 4 but this is the current aspect of the table:
Current HTML code:
<div class="row">
<div class="col-12">
<div class="table-responsive">
<table datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" class="table table-hover table-bordered">
<thead class="thead-colored thead-primary">
<tr class="text-center">
<th>ID</th>
<th>NICKNAME</th>
<th>EMAIL</th>
<th>REGISTRO</th>
<th>ESTATUS</th>
<th>ALTA</th>
<th>ACCIONES</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let usuario of usersArray" class="text-center">
<td>{{usuario.ID}}</td>
<td>{{usuario.NICKNAME}}</td>
<td>{{usuario.EMAIL}}</td>
<td>{{usuario.REGISTRO | date: 'dd-MMMM-yyyy' | uppercase}}</td>
<td>
<span class="bg-success pd-y-3 pd-x-10 text-white tx-11 tx-roboto">
{{usuario.ESTATUS | toStatusReadable}}
</span>
</td>
<td>{{usuario.PROVEEDORACCESO}}</td>
<td>
<div type="button" class="dropdown">
<a [routerLink]="" class="tx-gray-800 d-inline-block" data-toggle="dropdown">
<div class="ht-45 pd-x-20 bd d-flex align-items-center justify-content-center">
<span class="mg-r-10 tx-13 tx-medium">Opciones</span>
<img src="https://via.placeholder.com/500" class="wd-25 rounded-circle" alt="">
<i class="fas fa-angle-down"></i>
</div>
</a>
<div class="dropdown-menu pd-10 wd-200">
<nav class="nav nav-style-2 flex-column">
<a [routerLink]="" class="nav-link"><i class="icon fas fa-edit"></i> Editar datos</a>
</nav>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
TS File code for the table:
export class AdministradoresComponent implements OnInit, OnDestroy {
/* dtOptions: DataTables.Settings = {}; */
dtOptions: any = {};
dtTrigger: Subject<any> = new Subject<any>();
usersArray: Array<Users> = [];
constructor(
private devInfo: DevelopmentService,
private dtService: DatatableService,
private administradoresService: AdministradoresService
) {
this.ObtenerUsuariosSmartlive();
}
ngOnInit() {
document.getElementById('mainSystemPanel').removeAttribute('class');
document.getElementById('mainSystemPanel').className = 'br-mainpanel';
this.dtOptions = this.dtService.getDataTableConfig();
}
ngOnDestroy() {
this.dtTrigger.unsubscribe();
}
async ObtenerUsuariosSmartlive() {
const usuarios = <any []> await this.administradoresService.getSmartliveUsersList();
for ( let i = 0; i < usuarios.length; i++) {
this.usersArray.push(JSON.parse(usuarios[i]));
}
this.dtTrigger.next();
}
}
The service to provide config of the table:
export class DatatableService {
constructor() {
}
getDataTableConfig() {
return {
language: {
url: 'assets/content/smartlive/spanish.json'
},
responsive: true
};
}
}
angular.json snippet:
"styles": [
"node_modules/#fortawesome/fontawesome-free/css/all.min.css",
"node_modules/animate.css/animate.min.css",
"src/assets/content/template/lib/ionicons/css/ionicons.min.css",
"src/assets/content/template/lib/rickshaw/rickshaw.min.css",
"src/assets/content/template/lib/select2/css/select2.min.css",
"src/assets/content/template/css/bracket.css",
"src/assets/content/template/css/bracket.oreo.css",
"node_modules/datatables.net-dt/css/jquery.dataTables.min.css",
"node_modules/datatables.net-bs/css/dataTables.bootstrap.min.css",
"node_modules/datatables.net-responsive-dt/css/responsive.dataTables.min.css",
"src/styles.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"node_modules/datatables.net-bs/js/dataTables.bootstrap.min.js",
"node_modules/datatables.net-responsive/js/dataTables.responsive.min.js"
]
I already installed all the packages files for the datatable but i can't set a correct 100% of width and always the pagination and search input have a bad location over the table.
A bit late but it might help someone else ;-)
Try:
npm install datatables.net-bs4
Then call:
"styles": [
...
"./node_modules/datatables.net-bs4/css/dataTables.bootstrap4.min.css",
...
],
"scripts": [
...
"./node_modules/datatables.net-bs4/js/dataTables.bootstrap4.min.js",
...
],
Related
So I'm trying to make a table that use ngFor for every data in the API. I tried a tutorial in Youtube video and it is working fine. Now I'm trying it with the API given to me, but the problem is the data is not coming out in the table
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<!-- TABLE: LATEST ORDERS -->
<div class="card">
<div class="card-header border-transparent">
<h3 class="card-title">Latest Orders</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="remove">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- /.card-header -->
<div class="card-body p-0">
<div class="table-responsive">
<table class="table m-0">
<thead>
<tr>
<th>Order ID</th>
<th>Item</th>
<th>Status</th>
<th>Popularity</th>
</tr>
</thead>
<tbody>
<tr>
<td>OR9842</td>
<td>Call of Duty IV</td>
<td><span class="badge badge-success">Shipped</span></td>
<td>
<div class="sparkbar" data-color="#00a65a" data-height="20">90,80,90,-70,61,-83,63</div>
</td>
</tr>
<tr *ngFor="let campaign of campaigns | async">
<td>{{campaign.id}}</td>
<td>{{campaign.name}}</td>
<td><span class="badge badge-warning">Pending</span></td>
<td>
<div class="sparkbar" data-color="#f39c12" data-height="20">90,80,-90,70,61,-83,68</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- /.table-responsive -->
</div>
<!-- /.card-body -->
<div class="card-footer clearfix">
</div>
<!-- /.card-footer -->
</div>
<!-- /.card -->
</div>
<!-- /.col -->
</div> <!-- /.row -->
campaign.component.ts
import { Component, OnInit } from '#angular/core';
import { GetServiceService } from '../get-service.service';
#Component({
selector: 'app-campaign',
templateUrl: './campaign.component.html',
styleUrls: ['./campaign.component.css']
})
export class CampaignComponent implements OnInit {
campaigns;
constructor(
private campaignService: GetServiceService,
) { }
ngOnInit(): void {
this.campaigns = this.campaignService.getCampaign();
}
}
get-service.service.ts
import { Injectable } from '#angular/core';
import { HttpClient } from '#angular/common/http';
#Injectable({
providedIn: 'root'
})
export class GetServiceService {
constructor(
private http: HttpClient
) { }
getCampaign(){
return this.http.get('https://emaillead.aturtoko.id/api/v1/campaign')
}
}
So my expectation is that this code would give out the list of data in my API (ignore the first ). What actually happen is that the table only show the first , which means the data is not showing up on the table.
The error in the console is
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
at NgForOf.ngDoCheck (common.js:3184)
at callHook (core.js:2536)
at callHooks (core.js:2495)
at executeCheckHooks (core.js:2427)
at refreshView (core.js:9474)
at refreshComponent (core.js:10636)
at refreshChildComponents (core.js:9261)
at refreshView (core.js:9515)
at refreshEmbeddedViews (core.js:10590)
at refreshView (core.js:9489)
The data in api from postman get is
{
"success": true,
"message": "success",
"data": [
{
"id": 1,
"name": "buattoko"
},
{
"id": 2,
"name": "omnipos"
},
{
"id": 3,
"name": "pluscampaign"
}
]
}
what do I need to do to get the data to the table?
Add pipe and map rxjs operator to transform the result as response.data.
get-service.service.ts
import { map } from 'rxjs/operators';
getCampaign() {
return this.http.get('https://emaillead.aturtoko.id/api/v1/campaign')
.pipe(map((response: any) => response.data));
}
Sample Solution on StackBlitz
I get this ExpressionChangedAfterItHasBeenCheckedError when i am using random numbers progress bar in my html grid table.It says "ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: some value. Current value: some value.". Someone please help me with the issue.
<nav class="navbar navbar-expand-sm bg-primary navbar-dark">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" routerLinkActive="active">
<button class="btn btn-primary" (click)="goToAddUser()">Add User</button>
</a>
</li>
</ul>
</nav>
<div class="panel panel-primary">
<div class="panel-heading">
<h2>User List</h2>
</div>
<div class="panel-body">
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Actions</th>
<th>Progress</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let user of users | async">
<td>{{user.firstname}}</td>
<td>{{user.lastname}}</td>
<td>{{user.email}}</td>
<td>
<button (click)="goToEditUser(user.id)" class="btn btn-info">Update</button>
<button (click)="deleteUser(user.id)" class="btn btn-danger" style="margin-left: 10px">Delete</button>
<button (click)="goToViewUser(user.id)" class="btn btn-info" style="margin-left: 10px">Details</button>
</td>
<td>
<mat-progress-bar [value]="number" style="margin-right: 300px"></mat-progress-bar>
{{ number }}%
</td>
</tr>
</tbody>
</table>
</div>
</div>
The getRandomNumber() return value changes after angular change detection already checked its value. To understand the error better, read this article:
https://hackernoon.com/everything-you-need-to-know-about-the-expressionchangedafterithasbeencheckederror-error-e3fd9ce7dbb4
Here's one solution, make a class field called randomNumber and assign it to the value of getRandomNubmer().
class YourComponentClass { randomNumber : number = this.getRandomNumber(); ... }
In Html
<td> <mat-progress-bar [value]="randomNumber" style="margin-right: 300px">
</mat-progress-bar> {{ randomNumber }} </td>
if you want to change your randomNumber just create a click event handler to reassign randomNumber to getRandomNumber() method
You need to manually check for changes.
// Import
import { Component, OnInit, ChangeDetectorRef } from '#angular/core';
// Inject
constructor(private cd: ChangeDetectorRef)
// Call after making changes in component
someMethod() {
this.cd.detectChanges();
}
I have one small label where i am showing total result count of one table data.below i am using one table,On that i'm showing list of data.when i'm deleting one row in table,table is refreshing but in that label result count is not refreshing.Here is my data..
import { VsnApplicationsServiceProxy, VsnApplicationDto , CreateOrEditVsnApplicationDto } from '#shared/service-proxies/service-proxies';
#Component({
selector: 'vsn-applicationmappings',
templateUrl: './applicationmappings.component.html',
styleUrls: ['./applicationmappings.component.less'],
encapsulation: ViewEncapsulation.None,
animations: [appModuleAnimation()]
})
export class ApplicationMappingsComponent extends AppComponentBase implements OnInit {
applications: any;
constructor(
injector: Injector,
private _vsnApplicationsServiceProxy: VsnApplicationsServiceProxy,
private _activatedRoute: ActivatedRoute,
) {
super(injector);
}
ngOnInit() {
this._vsnApplicationsServiceProxy.getAll("", "", "", "", "", "", "", 0, 100).subscribe((Applications: any) => {
this.applications = Applications.totalCount;
console.log(' application value', Applications.totalCount);
});
}
getVsnApplications(event?: LazyLoadEvent) {
if (this.primengTableHelper.shouldResetPaging(event)) {
this.paginator.changePage(0);
return;
}
this.primengTableHelper.showLoadingIndicator();
this._vsnApplicationsServiceProxy.getAll(
this.filterText,
this.nameFilter,
this.businessNameFilter,
this.vsnApplicationTypeNameFilter,
this.vsnApplicationCategoryNameFilter,
this.vsnApplicationSubCategoryNameFilter,
this.primengTableHelper.getSorting(this.dataTable),
this.primengTableHelper.getSkipCount(this.paginator, event),
this.primengTableHelper.getMaxResultCount(this.paginator, event)
).subscribe(result => {
this.primengTableHelper.totalRecordsCount = result.totalCount;
this.primengTableHelper.records = result.items;
this.primengTableHelper.hideLoadingIndicator();
});
}
reloadPage(): void {
this.paginator.changePage(this.paginator.getPage());
}
createVsnApplication(): void {
this.createOrEditVsnApplicationModal.show();
}
deleteVsnApplication(vsnApplication: VsnApplicationDto): void {
this.message.confirm(
'',
(isConfirmed) => {
if (isConfirmed) {
this._vsnApplicationsServiceProxy.delete(vsnApplication.id)
.subscribe(() => {
this.reloadPage();
this.notify.success(this.l('SuccessfullyDeleted'));
});
}
}
);
}
<div class="col-sm-2">
<div class="box">
<div><br><br>
<h4>{{applications}}</h4>
</div>
<div> <span>
<h6>Applications</h6>
</span></div>
</div>
</div>
<div class="m-content">
<div class="m-portlet m-portlet--mobile">
<div class="m-portlet__body">
<div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
<p-table #dataTable (onLazyLoad)="getVsnApplications($event)" [value]="primengTableHelper.records"
rows="{{primengTableHelper.defaultRecordsCountPerPage}}" [paginator]="false" [lazy]="true"
[scrollable]="true" ScrollWidth="100%" [responsive]="primengTableHelper.isResponsive"
[resizableColumns]="primengTableHelper.resizableColumns">
<ng-template pTemplate="header">
<tr>
<th style="width: 150px" pSortableColumn="vsnApplicationType.name">
{{l("ApplicationName")}}
<p-sortIcon field="vsnApplication.name"></p-sortIcon>
</th>
<th style="width: 130px"
[hidden]="!isGrantedAny('Pages.Administration.VsnApplicationTypes.Edit', 'Pages.Administration.VsnApplicationTypes.Delete')">
{{l('Actions')}}</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-record="$implicit">
<tr>
<td style="width:150px">
<span class="ui-column-title"> {{l("ApplicationName")}}</span>
{{record.vsnApplication.businessName}}
</td>
<td style="width: 130px"
[hidden]="!isGrantedAny('Pages.Administration.VsnApplications.Edit', 'Pages.Administration.VsnApplications.Delete')">
<div class="btn-group dropdown" dropdown container="body">
<button class="dropdown-toggle btn btn-sm btn-primary" dropdownToggle>
<i class="fa fa-cog"></i><span class="caret"></span> {{l("Actions")}}
</button>
<ul class="dropdown-menu" *dropdownMenu>
<li>
<a href="javascript:;"
(click)="viewVsnApplicationModal.show(record)">{{l('View')}}</a>
</li>
<li>
<a href="javascript:;"
*ngIf="permission.isGranted('Pages.Administration.VsnApplicationTypes.Edit')"
(click)="createOrEditVsnApplicationModal.show(record.vsnApplication.id)">{{l('Edit')}}</a>
</li>
<li>
<a href="javascript:;"
*ngIf="permission.isGranted('Pages.Administration.VsnApplicationTypes.Delete')"
(click)="deleteVsnApplication(record.vsnApplication)">{{l('Delete')}}</a>
</li>
</ul>
</div>
</td>
</tr>
</ng-template>
</p-table>
<div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
{{l('NoData')}}
</div>
<div class="primeng-paging-container">
<p-paginator rows="{{primengTableHelper.defaultRecordsCountPerPage}}" #paginator
(onPageChange)="getVsnApplications($event)"
[totalRecords]="primengTableHelper.totalRecordsCount"
[rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
</p-paginator>
<span class="total-records-count">
{{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
</span>
</div>
</div>
</div>
</div>
<createOrEditVsnApplicationModal #createOrEditVsnApplicationModal (modalSave)="getVsnApplications()">
</createOrEditVsnApplicationModal>
<viewVsnApplicationModal #viewVsnApplicationModal></viewVsnApplicationModal>
</div>
When deleting one row, the table is refreshing and showing updated records.but in that result count lable is not refreshing.I searched in stack overflow,I found that we have to give like splice(id,1)
but it is not working,any suggestions would great help..
I am showing real time data in a HTML table by getting the data from back-end socket developed using Node.js, which sends the data of 200 row (objects) every second which haves some object's value changed.
When I am trying to display or render those data in HTML table, the browser crashes and displays nothing.
I am using Angular and D3 table libraries to do. The code is attached below. Please help me with some ways to fix this or even some better idea to resolved this issue.
My Component.ts File
import { Component, OnInit } from '#angular/core';
import { HttpService } from '../../Service/http.service';
import { SymbolClass } from 'src/app/Model/Symbol';
import { SocketService } from 'src/app/Service/socket.service';
import { ResponseClass } from 'src/app/Model/Response';
import * as d3 from 'd3';
import { Subscription } from 'rxjs';
import { DataSetClass } from 'src/app/Model/DataSet';
import { ChangeDetectorRef } from '#angular/core';
import { BidData } from 'src/app/Model/DataBid';
#Component({
selector: 'dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
private symbolList: SymbolClass[];
private symbolSelected = "XBTUSD";
private url = 'http://188.166.85.186:7000';
private socket;
private dataSetlist: ResponseClass;
private sub: Subscription;
private askDept: DataSetClass[];
private bidDept: BidData[];
constructor(private httpService: HttpService, private socketService: SocketService, private changeDetectorRef: ChangeDetectorRef) {
}
ngOnInit() {
var leftTable = d3.select('#leftTable')
var rightTable = d3.select('#rightTable')
leftTable.append('tbody')
rightTable.append('tbody')
this.httpService.getSymbol()
.subscribe(data => {
this.symbolList = data
this.socketService.emitAfterSymbolChange(this.symbolSelected);
this.sub = this.socketService.getDataResponse()
.subscribe(data => {
this.dataSetlist = data
this.askDept = data.askDepth
this.setupData(this.askDept,'#leftTable')
this.bidDept = data.bidDepth
this.setupData(this.bidDept,'#rightTable')
});
});
}
private dev = function(){
this.setupData(this.randomizeData(),'#leftTable')
this.setupData(this.randomizeData(),'#rightTable')
}
private setupData = function (data: any,tableType: String) {
var rows = d3.select(tableType).select('tbody')
.selectAll('tr')
.data(data, function (d) {
return d.title;
})
rows.exit().remove()
var entertd = rows.enter()
.append('tr')
.selectAll('td')
.data(function (d) {
return d3.map(d).values();
})
.enter()
.append('td')
.append('div')
.append('span')
.text(function(d){
return d;
})
var td = rows.selectAll('td')
.data(function (d) {
return d3.map(d).entries();
})
.attr('class', function (d) { return d.key })
td.select('span')
.text(function (d) {
if (d.key == 'conversion_rate') {
return Math.round(100 * d.value) + '%'
}
return d.value
})
}
}
My component.html file
<div class="container" style="margin-top: 100px; margin-bottom: 100px;">
<select class="form-control">
<option *ngFor="let sym of symbolList">{{sym}}</option>
</select>
<div class="row" style="margin:20px 0px;">
<button (click)="dev()" type="button">Update Data</button>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 mt-2">
<div class="chartDoug bg-dark">
<span class="headTip text-nowrap" style="font-size:20px">Live Order Book!</span>
<div id="myChart"></div>
</div>
</div>
</div>
<div class="row">
<div class="col col-xs-12 col-sm-6 col-md-3 col-lg-3">
<h4 style="text-align:center; color:red;float:left;margin-left:10px;">Volumn:</h4>
<h4 style="text-align:right; color:red;float:left;margin-left:5px;" class="volumn"></h4>
</div>
<div class="col col-xs-12 col-sm-6 col-md-3 col-lg-3">
<h4 style="text-align:center; color:green;float:left;margin-left:10px;">Last Price:</h4>
<h4 style="text-align:right; color:green;float:left;margin-left:5px;" class="lastprice"></h4>
</div>
<div class="col col-xs-12 col-sm-6 col-md-3 col-lg-3">
<h4 style="text-align:center; color:red;float:left;margin-left:10px;">HIGH:</h4>
<h4 style="text-align:right; color:red;margin-left:5px;float:left;" class="high"></h4>
</div>
<div class="col col-xs-12 col-sm-6 col-md-3 col-lg-3">
<h4 style="text-align:center; color:green;float:left;margin-left:10px;">LOW:</h4>
<h4 style="text-align:right; color:green;margin-left:5px;float:left;" class="low"></h4>
</div>
</div>
<div class="row">
<div class="col col-xs-12 col-sm-12 col-md-6 col-lg-6">
<h2 style="text-align:center; color:green;">BUY</h2>
<h4 style="text-align:right; color:green;" class="buy_total_amount"></h4>
<table id="leftTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th style="text-align: center;">No</th>
<th style="text-align: center;">Price</th>
<th style="text-align: center;">Quantity</th>
<th style="text-align: center;">Total Amount</th>
</tr>
</thead>
<tbody style="text-align: right;" class="buy">
</tbody>
</table>
</div>
<div class="col col-xs-12 col-sm-12 col-md-6 col-lg-6">
<h2 style="text-align:center; color:red;">SELL</h2>
<h4 style="text-align:right; color:red;" class="sell_total_amount"></h4>
<table id="rightTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th style="text-align: center;">No</th>
<th style="text-align: center;">Price</th>
<th style="text-align: center;">Quantity</th>
<th style="text-align: center;">Total Amount</th>
</tr>
</thead>
<tbody style="text-align: right;" class="sell">
</tbody>
</table>
</div>
</div>
</div>
import React from "react";
import {
Button,
Form,
FormGroup,
Label,
Input,
FormText,
Row
} from "reactstrap";
import Icon from "react-icons-kit";
import { filter } from "react-icons-kit/fa/filter";
import { pencil, bin, search } from "react-icons-kit/icomoon";
import { ic_delete, ic_create } from "react-icons-kit/md";
import { Link } from "react-router-dom";
import { activeStyle } from "../projects/Projects.css";
import {
orange,
contentStyle,
displayContainer,
pageHeading,
hrStyle,
buttonStyle,
floatRight1,
exampletable,
savebtn1,
bankdiv,
btnstyle
} from "../Layout.css";
import { hyperLink } from "../settings/LayoutSettings.css";
import { Header } from "../Header";
import { Footer } from "../Footer";
import $ from "jquery";
var result = [];
var URL = "http://localhost:3033/";
var parsed = "";
export class ClaimList extends React.Component {
constructor() {
super();
this.state = {
data: []
};
}
componentDidMount() {
this.Claimlist();
}
Claimlist() {
alert("called");
$.ajax({
url: URL + "/ClaimList",
type: "GET",
dataType: "json",
ContentType: "application/json",
success: function(parsed) {
parsed = JSON.stringify(parsed);
console.log(parsed);
for (var x in parsed) {
result.push(parsed[x]);
}
result = $.parseJSON(parsed);
data = JSON.stringify(data);
this.setState(result);
console.log("hello ramesh");
}.bind(this),
error: function(jqXHR) {
console.log(jqXHR);
}.bind(this)
});
}
renderProducts() {
return this.state.result.map(product => {
return (
<tr>
<td>{product.ID}</td>
<td>{product.ExpenseName}</td>
<td>{product.Amount}</td>
</tr>
);
});
}
render() {
return (
<div>
<table>
<tbody>
{this.state.result.map(function(item, key) {
return (
<tr key={key.id}>
<td>{item.ID}</td>
<td>{item.ExpenseName}</td>
<td>{item.Amount}</td>
<td>{item.Description}</td>
</tr>
);
})}
</tbody>
</table>
<Header />
<div className={displayContainer}>
<p className={pageHeading}>Claims</p>
<hr className={hrStyle} />
<span className={floatRight1}>
<form class="form-row" method="GET">
<input type="search" placeholder="Search" />
<div
class="dropdown"
style={{ position: "relative", left: "-1vw" }}
>
<button
class="btn btn-outline-light"
type="button"
id={btnstyle}
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
<Icon icon={filter} />
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item">Employee ID</a>
<a class="dropdown-item">Expense Title</a>
<a class="dropdown-item">Date</a>
<a class="dropdown-item">Amount</a>
</div>
</div>
</form>
</span>
<table class="table table-bordered table-striped table-responsive-md">
<thead>
<tr className={orange}>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Expense Title</th>
<th>Description</th>
<th>Amount</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{/* {this.MyTableGrid()} */}
{this.renderProducts()}
</tbody>
</table>
<div
className={bankdiv}
style={{ marginTop: "7vw", marginLeft: "-7.7vw" }}
>
<Link to="/AddClaims">
<button className="btn btn-outline-warning">Add New Claim</button>
</Link>
</div>
</div>
<Footer />
</div>
);
}
}
I'm unable to fetch the data from json and map it into the datagrid. I'm using reactjs and json to get the values from the backend(go).localhost:3033 is my go server and mysql is my database.
I'm getting an error as
Uncaught TypeError: Cannot read property 'map' of undefined
maybe by simply set a default value for result in your constructor that for the moment is undefined in the first render of your class :
constructor() {
super();
this.state = {
data: [],
result: []
};
}
Although as #Jitendra suggest, you can use JSX syntax
render() {
return {this.state.result && <Fragment> ... </Fragment>}
}
You needs to check inside render if this.state.result is null or not before mapping it.
render(){
if (!this.state.result)
return
else
{do other stuffs}