How to format (customize) data tables in react - reactjs

I am new to react and datatables and currently working on my final year project
I have retrieved the data and managed to populate data into datatable but don't know how to format it.
How to format datatable like this:
image
Code: https://codesandbox.io/s/ry6910y4jn?fontsize=14
Any suggestion hint would be helpful, thanks in advance.

Try giving this a shot by running the snippet below. The trick is to use rowspan.
That said, using React to render your multi-row, a naive approach might look something like:
const renderMultiRow = (code, date, rice, wheat, jaggery) => {
return (
<React.Fragment>
<tr>
<td rowspan="2">{code}</td>
<td rowspan="2">{date}</td>
<td>Stock</td>
<td>{rice.stock}</td>
<td>{wheat.stock}</td>
<td>{jaggery.stock}</td>
</tr>
<tr>
<td>Daily Use</td>
<td>{rice.use}</td>
<td>{wheat.stock}</td>
<td>{jaggery.stock}</td>
</tr>
<React.Fragment>
)
}
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
padding: 5px;
}
<table>
<thead>
<th>Code</th>
<th>Date</th>
<th>Category</th>
<th>Rice</th>
<th>Wheat</th>
<th>Jaggery</th>
</thead>
<tbody>
<tr>
<td rowspan="2">1234</td>
<td rowspan="2">2019-05-11</td>
<td>Stock</td>
<td>50</td>
<td>50</td>
<td>50</td>
</tr>
<tr>
<td>Daily Use</td>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td rowspan="2">5678</td>
<td rowspan="2">2019-05-12</td>
<td>Stock</td>
<td>30</td>
<td>30</td>
<td>30</td>
</tr>
<tr>
<td>Daily Use</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>

Related

How can I remove the thick line from the table header row bottom

I just follow the example for creating a table with the bootstrap Table element.
Here is my StackBlitz, I wonder why a thick black line exists at the bottom of the table header.
However, the example site does not have a thick black line exists at the bottom of the table header.
Is there something wrong? is it possible to remove the thick black line from the bottom of the table header?
It is border assigned by bootstrap when you use Table group dividers. See Bootstrap docs for more details.
To get remove it add borderTop: 'none' to tbody. So updated component looks like below
import React from 'react';
import Table from 'react-bootstrap/Table';
export default function App() {
return (
<div className="m-4">
<Table striped bordered hover>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody style={{ borderTop: 'none' }}>
<tr>
<td>1</td>
<td>Mark</td>
<td>Otto</td>
<td>#mdo</td>
</tr>
<tr>
<td>2</td>
<td>Jacob</td>
<td>Thornton</td>
<td>#fat</td>
</tr>
<tr>
<td>3</td>
<td colSpan={2}>Larry the Bird</td>
<td>#twitter</td>
</tr>
</tbody>
</Table>
</div>
);
}
Stackblitz Reproduction: https://react-ue5ckm.stackblitz.io
You have to need override the following style
.table>:not(:first-child) {
border-top: 2px solid currentColor;
}
to remove border
.table>:not(:first-child) {
border-top: none;
}

hide/show column not working for datatable-colvis-basic using angular js

I am trying to hide/show columns class datatable-colvis-basic but it is hiding only the table header not data. I think because my dynamic table data from angular js. what is solution for that.
<table id="table_id" class="table datatable-colvis-basic" id="DataTables_Table_0 " role="grid" aria-describedby="DataTables_Table_0_info" ng-show="numberLoad">
<thead>
<tr>
<th>#</th>
<th>Order Id</th>
<th>SKU</th>
<th>Vendor Name</th>
<th>Recived MP</th>
<th>Placed On MP</th>
<th>Placed On Date</th>
</tr>
</thead>
<tbody>
<tr dir-paginate="mplist in getMpList | itemsPerPage:mpreportinfo.itemsPerPage" current-page="mpreportinfo.currentPage" total-items="total_count">
<td>{{$index + 1}}</td>
<td>{{mplist.order_id}}</td>
<td>{{mplist.sku}}</td>
<td>{{mplist.vendor_name}}</td>
<td>{{mplist.order_source_name}}</td>
<td>Amazon</td>
<td>{{mplist.placed_date}}</td>
</tr>
</tbody>
</table>
please check attached image
Put the ng-show in the element inside the table.
<table id="table_id" class="table datatable-colvis-basic" id="DataTables_Table_0 " role="grid" aria-describedby="DataTables_Table_0_info">
<thead>
<tr>
<th>#</th>
<th>Order Id</th>
<th>SKU</th>
<th>Vendor Name</th>
<th>Recived MP</th>
<th ng-show="numberLoad">Placed On MP</th>
<th>Placed On Date</th>
</tr>
</thead>
<tbody>
<tr dir-paginate="mplist in getMpList | itemsPerPage:mpreportinfo.itemsPerPage" current-page="mpreportinfo.currentPage" total-items="total_count">
<td>{{$index + 1}}</td>
<td>{{mplist.order_id}}</td>
<td>{{mplist.sku}}</td>
<td>{{mplist.vendor_name}}</td>
<td>{{mplist.order_source_name}}</td>
<td ng-show="numberLoad">Amazon</td>
<td>{{mplist.placed_date}}</td>
</tr>
</tbody>
</table>
Here you have an example of show or hide columns with angularJS and ng-show.
I hope it helps you.
https://codepen.io/salva341/pen/oqyxKW

Displaying data from local JSON based on a condition in AngularJS

I wanted to know how to display the data by reading a local json. In a row having 4 columns, 2 columns are coming from 1 array and 2 are coming from a different array.
HTML:
<table class="table table-striped table-bordered">
<thead>
<tr>
<th></th>
<th>IT</th>
<th>IT User</th>
<th>CT</th>
<th>CT User</th>
</tr>
</thead>
<tbody>
<tr>
<td class="currency">Type A</td>
<td class="currency"></td>
<td class="currency"></td>
<td class="currency"></td>
<td class="currency"></td>
</tr>
<tr>
<td class="currency">Type B</td>
<td class="currency"></td>
<td class="currency"></td>
<td class="currency"></td>
<td class="currency"></td>
</tr>
</tbody>
JSON:
{
"intr_liab":[
{
"ty":"typeA",
"it":"100",
"ct":"200"
},
{
"ty":"typeAITUser",
"it":"300",
"ct":"400"
},
{
"ty":"typeB",
"it":"500",
"ct":"600"
},
{
"ty":"typeBITUser",
"it":"700",
"ct":"800"
}
]
}
So data in the table should come as:
<body ng-controller="MainCtrl">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th></th>
<th>IT</th>
<th>IT User</th>
<th>CT</th>
<th>CT User</th>
</tr>
</thead>
<tbody>
<tr>
<td class="currency">Type A</td>
<td class="currency">100</td>
<td class="currency">300</td>
<td class="currency">200</td>
<td class="currency">400</td>
</tr>
<tr>
<td class="currency">Type B</td>
<td class="currency">500</td>
<td class="currency">700</td>
<td class="currency">600</td>
<td class="currency">800</td>
</tr>
</tbody>
</table>
</body>
Please refer this Plunker for more clarity:
https://plnkr.co/edit/USt7nXmwCTRcCfOx8sma
Please replace the HTML code with following. I hope it will help you.
<body ng-controller="MainCtrl">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th></th>
<th>IT</th>
<th>IT User</th>
<th>CT</th>
<th>CT User</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in intLiab">
<td class="currency">{{item.ty}}</td>
<td class="currency">{{item.it}}</td>
<td class="currency"></td>
<td class="currency">{{item.ct}}</td>
<td class="currency"></td>
</tr>
</tbody>
</table>
</body>
Please comment if you need more specific answer.

Using DTOptionsBuilder to hide header table using Angular DataTables

Normally according to the documentation of Datatables I think it is necessary to give a value false to fixedHeader
.withOption('fixedHeader', false) but it does not work
Try hack using css
.inventory_related thead {
display: none;
}
<table>
<thead>
<th>header 1</th>
<th>header 2</th>
</thead>
<tbody>
<td>row value 1</td>
<td>row value 2</td>
</tbody>
</table>
<table class='inventory_related'>
<thead>
<th>header</th>
<th>header 2</th>
</thead>
<tbody>
<td>row value 3</td>
<td>row value 4</td>
</tbody>
</table>

rendering a grid from a table: "this.mainBody is undefined"

I have a static html table on a page and i would like to transform it to a grid; so i applied this function after loading the table:
function createTable() {
// create the grid
var grid = new Ext.ux.grid.TableGrid("tabella-colocazioni", {
stripeRows: true // stripe alternate rows
});
grid.render();
}
I got this piece of code from here: http://www.java2s.com/Code/JavaScript/Ext-JS/CreateagridwithfromanexistingunformattedHTMLtable.htm . The result is the error "this.mainBody is undefined on ext-all-debug.js" on FireBug and the grid is empty. The html code of the table is this:
<table cellspacing="0" id="tabella-colocazioni">
<thead>
<tr style="background:#eeeeee;">
<th>Colocazione</th>
<th>Frequenza</th>
</tr>
</thead>
<tbody>
<tr>
<td>plusquam patria</td>
<td>1</td>
</tr>
<tr>
<td>patria pietate</td>
<td>1</td>
</tr>
<tr>
<td>Et patria</td>
<td>1</td>
</tr>
<tr>
<td>patria prohibet</td>
<td>1</td>
</tr>
<tr>
<td>Multos patria</td>
<td>1</td>
</tr>
<tr>
<td>patria reddidit</td>
<td>1</td>
</tr>
<tr>
<td>patronum patria</td>
<td>1</td>
</tr>
<tr>
<td>patria moesta</td>
<td>1</td>
</tr>
</tbody>
</table>
What is the problem? Thank you very much.
Code looks fine. Are you sure that all includes are correct (check the Firebug Net tab)? Are you sure that the Ext version you are using is supported by the ux?

Resources