HTML Elements (tr &td) are showing on the client side - javascript

This is my first question on stack overflow, so I hope that I'm doing this correctly!
I'm working with pulling some data from an API, and then displaying that data in a table. So far my table is showing the HTML elements of <tr><td> + </tr></td>
Here is a photo to show my issue :
Photo of issue
Here is the code that I'm using :
const fetchUserz = async() => {
const response = await fetch(`https://jsonplaceholder.typicode.com/users`);
const data = await response.json();
for (let i = 0; i < data.length; i++) {
let table = document.getElementById(`myTable`);
let row = `<tr>
<td>${data[i].name}</td>
<td>${data[i].email}</td>
</tr>`;
table.innerHTML += row;
table.append(row);
}
}
fetchUserz();
Here is the HTML :
<body class="text-white bg-secondary mb-3 bg-gradient" id="body">
<main>
<header id="head">
<h2>API Project</h2>
</header>
<table>
<thead>
<tr>
<th> Names of People </th>
<th> Emails of People </th>
</tr>
</thead>
const fetchUserz = async() => {
const response = await fetch(`https://jsonplaceholder.typicode.com/users`);
const data = await response.json();
// console.log(data)
for(let i = 0; i < data.length; i++){
let table = document.getElementById(`myTable`);
let row = `<tr>
<td>${data[i].name}</td>
<td>${data[i].email}</td>
</tr>`;
table.innerHTML += row;
table.append(row);
}
}
fetchUserz();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset = "UTF-8">
<title>Native Awakenings</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/css/bootstrap.css" rel="stylesheet" crossorigin="anonymous">
<link href="/css/stylesheet.css" rel="stylesheet">
</head>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="/index.html">Native Awakenings</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/index.html">Home</a>
</li>
<li class="nav-item">
About Me
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Concious Creations
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="blog-posts.html">Blog Posts</a></li>
<li><a class="dropdown-item" href="offerings.html">Offerings</a></li>
<li><a class="dropdown-item" href="podcasts.html">Podcasts</a></li>
<li><a class="dropdown-item" href="yoga-videos.html">Yoga Videos</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="https://gitlab.com/Gregg-Hendrix/how-i-became-a-software-engineer" target="_blank">How I Became A Software Engineer</a></li>
</ul>
</li>
</ul>
<span class="navbar-text">
May Presence Be Our Purpose
</span>
</div>
</div>
</nav>
<body class="text-white bg-secondary mb-3 bg-gradient" id="body">
<main>
<header id="head">
<h2>API Project</h2>
</header>
<table>
<thead>
<tr>
<th> Names of People </th>
<th> Emails of People </th>
</tr>
</thead>
<tbody id="myTable">
</tbody>
</main>
<footer class="card-footer bg-dark bg-gradient navbar-dark text-light" id="footer"> If you want to support Native Awakenings, please do one kind act! Remember that you are unconditionally loved. My social media: Insta: #Greggyogi, Email: gregg#gregghendrix.com, Facebook: Gregg Hendrix</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>
<script src="/js/weather.js"></script>
</body>
</html>
I've also added a snippet of EVERYTHING, any help would be massively appreciated :).

You immediate problem is using both innerHTML and append as covered in the comments
Let's go with innerHTML...
It's probably better to create your HTML string in one go rather than el.innerHTML += .... My gut feeling it that .innerHTML += will have pretty bad performance as each round will require an HTML parse and an HTML serialize.
const table = document.getElementById(`myTable`);
const rows = data.map(d=>`<tr>
<td>${data[i].name}</td>
<td>${data[i].email}</td>
</tr>`);
table.innerHTML = rows.join("");

You can create your HTML string as below.
const fetchUserz = async() => {
const data = [
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere#april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "Shanna#melissa.tv",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
},
"phone": "010-692-6593 x09125",
"website": "anastasia.net",
"company": {
"name": "Deckow-Crist",
"catchPhrase": "Proactive didactic contingency",
"bs": "synergize scalable supply-chains"
}
},
{
"id": 3,
"name": "Clementine Bauch",
"username": "Samantha",
"email": "Nathan#yesenia.net",
"address": {
"street": "Douglas Extension",
"suite": "Suite 847",
"city": "McKenziehaven",
"zipcode": "59590-4157",
"geo": {
"lat": "-68.6102",
"lng": "-47.0653"
}
},
"phone": "1-463-123-4447",
"website": "ramiro.info",
"company": {
"name": "Romaguera-Jacobson",
"catchPhrase": "Face to face bifurcated interface",
"bs": "e-enable strategic applications"
}
},
{
"id": 4,
"name": "Patricia Lebsack",
"username": "Karianne",
"email": "Julianne.OConner#kory.org",
"address": {
"street": "Hoeger Mall",
"suite": "Apt. 692",
"city": "South Elvis",
"zipcode": "53919-4257",
"geo": {
"lat": "29.4572",
"lng": "-164.2990"
}
},
"phone": "493-170-9623 x156",
"website": "kale.biz",
"company": {
"name": "Robel-Corkery",
"catchPhrase": "Multi-tiered zero tolerance productivity",
"bs": "transition cutting-edge web services"
}
},
{
"id": 5,
"name": "Chelsey Dietrich",
"username": "Kamren",
"email": "Lucio_Hettinger#annie.ca",
"address": {
"street": "Skiles Walks",
"suite": "Suite 351",
"city": "Roscoeview",
"zipcode": "33263",
"geo": {
"lat": "-31.8129",
"lng": "62.5342"
}
},
"phone": "(254)954-1289",
"website": "demarco.info",
"company": {
"name": "Keebler LLC",
"catchPhrase": "User-centric fault-tolerant solution",
"bs": "revolutionize end-to-end systems"
}
},
{
"id": 6,
"name": "Mrs. Dennis Schulist",
"username": "Leopoldo_Corkery",
"email": "Karley_Dach#jasper.info",
"address": {
"street": "Norberto Crossing",
"suite": "Apt. 950",
"city": "South Christy",
"zipcode": "23505-1337",
"geo": {
"lat": "-71.4197",
"lng": "71.7478"
}
},
"phone": "1-477-935-8478 x6430",
"website": "ola.org",
"company": {
"name": "Considine-Lockman",
"catchPhrase": "Synchronised bottom-line interface",
"bs": "e-enable innovative applications"
}
},
{
"id": 7,
"name": "Kurtis Weissnat",
"username": "Elwyn.Skiles",
"email": "Telly.Hoeger#billy.biz",
"address": {
"street": "Rex Trail",
"suite": "Suite 280",
"city": "Howemouth",
"zipcode": "58804-1099",
"geo": {
"lat": "24.8918",
"lng": "21.8984"
}
},
"phone": "210.067.6132",
"website": "elvis.io",
"company": {
"name": "Johns Group",
"catchPhrase": "Configurable multimedia task-force",
"bs": "generate enterprise e-tailers"
}
},
{
"id": 8,
"name": "Nicholas Runolfsdottir V",
"username": "Maxime_Nienow",
"email": "Sherwood#rosamond.me",
"address": {
"street": "Ellsworth Summit",
"suite": "Suite 729",
"city": "Aliyaview",
"zipcode": "45169",
"geo": {
"lat": "-14.3990",
"lng": "-120.7677"
}
},
"phone": "586.493.6943 x140",
"website": "jacynthe.com",
"company": {
"name": "Abernathy Group",
"catchPhrase": "Implemented secondary concept",
"bs": "e-enable extensible e-tailers"
}
},
{
"id": 9,
"name": "Glenna Reichert",
"username": "Delphine",
"email": "Chaim_McDermott#dana.io",
"address": {
"street": "Dayna Park",
"suite": "Suite 449",
"city": "Bartholomebury",
"zipcode": "76495-3109",
"geo": {
"lat": "24.6463",
"lng": "-168.8889"
}
},
"phone": "(775)976-6794 x41206",
"website": "conrad.com",
"company": {
"name": "Yost and Sons",
"catchPhrase": "Switchable contextually-based project",
"bs": "aggregate real-time technologies"
}
},
{
"id": 10,
"name": "Clementina DuBuque",
"username": "Moriah.Stanton",
"email": "Rey.Padberg#karina.biz",
"address": {
"street": "Kattie Turnpike",
"suite": "Suite 198",
"city": "Lebsackbury",
"zipcode": "31428-2261",
"geo": {
"lat": "-38.2386",
"lng": "57.2232"
}
},
"phone": "024-648-3804",
"website": "ambrose.net",
"company": {
"name": "Hoeger LLC",
"catchPhrase": "Centralized empowering task-force",
"bs": "target end-to-end models"
}
}
]
let table = document.getElementById(`myTable`);
for(let i = 0; i < data.length; i++){
let row = '';
row +='<tr>';
row +='<td>'+data[i].name+'</td>';
row +='<td>'+data[i].email+'</td>';
row +='</tr>';
table.innerHTML += row;
}
}
fetchUserz();
<table>
<thead>
<tr>
<th> Names of People </th>
<th> Emails of People </th>
</tr>
</thead>
<tbody id="myTable">
</tbody>
<tbody id="myTable2">
</tbody>
</table>

const fetchUserz = async() => {
const response = await fetch(`https://jsonplaceholder.typicode.com/users`);
const data = await response.json();
// console.log(data)
for(let i = 0; i < data.length; i++){
let table = document.getElementById(`myTable`);
let row = `<tr>
<td>${data[i].name}</td>
<td>${data[i].email}</td>
</tr>`;
table.innerHTML += row;
}
}
fetchUserz();

Related

Multiple bootstrap tabs with DataTables. Child row only opening on one of the tabs

I have DataTables with child rows inside of 2 bootstrap tabs. The child rows do not consistently open inside the tab. They sometimes open on the first tab and sometimes on the second.
I want to create the container every time I click on the row and have it open. It sometimes opens in the second and sometimes in the first. It does not open in both tabs.
Here is my code:
let json1 = [{
"data": [
{
"id": "1",
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"id": "2",
"name": "Garrett Winters",
"position": "Accountant",
"salary": "$170,750",
"start_date": "2011/07/25",
"office": "Tokyo",
"extn": "8422"
},
{
"id": "3",
"name": "Ashton Cox",
"position": "Junior Technical Author",
"salary": "$86,000",
"start_date": "2009/01/12",
"office": "San Francisco",
"extn": "1562"
},
{
"id": "4",
"name": "Cedric Kelly",
"position": "Senior Javascript Developer",
"salary": "$433,060",
"start_date": "2012/03/29",
"office": "Edinburgh",
"extn": "6224"
},
{
"id": "5",
"name": "Airi Satou",
"position": "Accountant",
"salary": "$162,700",
"start_date": "2008/11/28",
"office": "Tokyo",
"extn": "5407"
}
]
}];
let json2 = [{
"data": [
{
"id": "1",
"name": "Harry Potter",
"position": "System Architect",
"salary": "$234,800",
"start_date": "2013/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"id": "2",
"name": "Ron Weasley",
"position": "Accountant",
"salary": "$170,777",
"start_date": "2011/09/25",
"office": "Tokyo",
"extn": "8422"
},
{
"id": "3",
"name": "Herminone Granger",
"position": "Junior Technical Author",
"salary": "$175,000",
"start_date": "2019/01/12",
"office": "San Francisco",
"extn": "1562"
},
{
"id": "4",
"name": "Neville Logbottom",
"position": "Senior Javascript Developer",
"salary": "$555,060",
"start_date": "2015/03/29",
"office": "Edinburgh",
"extn": "6224"
},
{
"id": "5",
"name": "Luna Lovegood",
"position": "Accountant",
"salary": "$200,700",
"start_date": "2017/11/28",
"office": "Tokyo",
"extn": "5407"
}
]
}];
var table;
const create_datatable =(js, tab) => {
js.forEach(d => {
table = $(`#${tab}`).DataTable( {
"bDestroy": true,
"responsive": true,
"autoWidth": false,
"data": d.data,
columns: [{
className: 'details-control',
orderable: false,
data: null,
defaultContent: '',
}, {
data: 'name', className:'names'
}, {
data: 'position', className:'position'
}, {
data: 'office', className:'office'
}, {
data: 'salary', className:'salary'
}]
} );
});
}
create_datatable(json1, 'example');
create_datatable(json2, 'example2');
const create_cont = (tab) => {
var containers = document.createElement('div');
containers.setAttribute("id", `${tab}_scatter`);
$(`#${tab} tbody`).on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = table.row( tr );
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
if ( table.row( '.shown' ).length ) $('.details-control', table.row( '.shown' ).node()).click();
$(`#${tab}_scatter`).html('test');
row.child(containers).show();
tr.addClass('shown');
}
});
}
create_cont('example');
create_cont('example2');
td.details-control {
background: url('../resources/details_open.png') no-repeat center center;
cursor: pointer;
}
tr.shown td.details-control {
background: url('../resources/details_close.png') no-repeat center center;
}
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#home">Home</a></li>
<li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
</ul>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<h3>Tab 1</h3>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Show Child Row</th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Salary</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div id="menu1" class="tab-pane fade">
<h3>Tab 2</h3>
<table id="example2" class="display" style="width:100%">
<thead>
<tr>
<th>Show Child Row</th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Salary</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
How do I fix it so that the row opens with my text('test') whenever I click the left-most column, a child row always happens?
I am creating a container every time I click on the row because I want to eventually add dynamic charts inside child row.
The issue is because you set table within the loop. Therefore it will only ever contain a reference to the last DataTable which was created.
To fix this, get the DataTable reference from the table element within the click handler:
let json1 = [{data:[{id:"1",name:"Tiger Nixon",position:"System Architect",salary:"$320,800",start_date:"2011/04/25",office:"Edinburgh",extn:"5421"},{id:"2",name:"Garrett Winters",position:"Accountant",salary:"$170,750",start_date:"2011/07/25",office:"Tokyo",extn:"8422"},{id:"3",name:"Ashton Cox",position:"Junior Technical Author",salary:"$86,000",start_date:"2009/01/12",office:"San Francisco",extn:"1562"},{id:"4",name:"Cedric Kelly",position:"Senior Javascript Developer",salary:"$433,060",start_date:"2012/03/29",office:"Edinburgh",extn:"6224"},{id:"5",name:"Airi Satou",position:"Accountant",salary:"$162,700",start_date:"2008/11/28",office:"Tokyo",extn:"5407"}]}];
let json2 = [{data:[{id:"1",name:"Harry Potter",position:"System Architect",salary:"$234,800",start_date:"2013/04/25",office:"Edinburgh",extn:"5421"},{id:"2",name:"Ron Weasley",position:"Accountant",salary:"$170,777",start_date:"2011/09/25",office:"Tokyo",extn:"8422"},{id:"3",name:"Herminone Granger",position:"Junior Technical Author",salary:"$175,000",start_date:"2019/01/12",office:"San Francisco",extn:"1562"},{id:"4",name:"Neville Logbottom",position:"Senior Javascript Developer",salary:"$555,060",start_date:"2015/03/29",office:"Edinburgh",extn:"6224"},{id:"5",name:"Luna Lovegood",position:"Accountant",salary:"$200,700",start_date:"2017/11/28",office:"Tokyo",extn:"5407"}]}];
const create_datatable = (js, tab) => {
js.forEach(d => {
$(`#${tab}`).DataTable({
"bDestroy": true,
"responsive": true,
"autoWidth": false,
"data": d.data,
columns: [{
className: 'details-control',
orderable: false,
data: null,
defaultContent: '',
}, {
data: 'name',
className: 'names'
}, {
data: 'position',
className: 'position'
}, {
data: 'office',
className: 'office'
}, {
data: 'salary',
className: 'salary'
}]
});
});
}
create_datatable(json1, 'example');
create_datatable(json2, 'example2');
const create_cont = (tab) => {
var containers = document.createElement('div');
containers.setAttribute("id", `${tab}_scatter`);
$(`#${tab} tbody`).on('click', 'td.details-control', function() {
var tr = $(this).closest('tr');
let table = tr.closest('table').DataTable(); // retrieve Datatable reference here
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
} else {
if (table.row('.shown').length) $('.details-control', table.row('.shown').node()).click();
$(`#${tab}_scatter`).html('test');
row.child(containers).show();
tr.addClass('shown');
}
});
}
create_cont('example');
create_cont('example2');
td.details-control {
background: url('../resources/details_open.png') no-repeat center center;
cursor: pointer;
}
tr.shown td.details-control {
background: url('../resources/details_close.png') no-repeat center center;
}
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#home">Home</a></li>
<li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
</ul>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<h3>Tab 1</h3>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Show Child Row</th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Salary</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div id="menu1" class="tab-pane fade">
<h3>Tab 2</h3>
<table id="example2" class="display" style="width:100%">
<thead>
<tr>
<th>Show Child Row</th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Salary</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>

jQuery DataTables - Force the Empty Table message after AJAX Call

I have a jquery-datatables set up, and using a custom search filter that functions as the standard keyword filter and a custom Item ID search which uses an ajax call to ping the back end and return a value, if any and then use that value to search the table in a specific column.
$.ajax({
url: 'the_url_to_lookup_itemID',
data: {
'engravingId': search(search is the value from the input field assigned to this variable)
},
dataType: 'jsonp',
success: function(data) {
console.log(data.assetId);
var assetId = data.assetId;
if (assetId != 0) {
searchResults.columns(2).search(assetId).draw();
} else {
searchResults.search(assetId).draw();
}
}
});
If the assetId equals "0" then the search just assumes its a keyword, since there is no record of the assetId existing. But instead of clearing out the table records and showing no results, there is no change. I'm assuming because "0" isn't enough for the filter to operate, so how can I force it? I want the user to see some result, "No matching records found" or something like that.
How can I force my jquery-datatables to display "No matching records found" after this custom search has failed to produce any results?
I am NOT looking for a custom message when there are no results. I am just looking for a way to force the display of this "No matching records found" when I execute my Ajax call and that function generates no results.
One way to force to display "No matching records found" message is by using the clear() and draw() methods.
If you need to change in runtime the message, you could use datatables.context[0].oLanguage.sEmptyTable attribute.
In your case is:
searchResults.context[0].oLanguage.sEmptyTable = "No matching records found...";
searchResults.clear().draw();
Something like this:
$(function() {
var dataSet = [
["Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800"],
["Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750"],
["Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000"],
["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "6224", "2012/03/29", "$433,060"],
["Airi Satou", "Accountant", "Tokyo", "5407", "2008/11/28", "$162,700"],
["Brielle Williamson", "Integration Specialist", "New York", "4804", "2012/12/02", "$372,000"],
["Herrod Chandler", "Sales Assistant", "San Francisco", "9608", "2012/08/06", "$137,500"],
["Rhona Davidson", "Integration Specialist", "Tokyo", "6200", "2010/10/14", "$327,900"],
["Colleen Hurst", "Javascript Developer", "San Francisco", "2360", "2009/09/15", "$205,500"],
["Sonya Frost", "Software Engineer", "Edinburgh", "1667", "2008/12/13", "$103,600"],
["Jena Gaines", "Office Manager", "London", "3814", "2008/12/19", "$90,560"],
["Quinn Flynn", "Support Lead", "Edinburgh", "9497", "2013/03/03", "$342,000"],
["Charde Marshall", "Regional Director", "San Francisco", "6741", "2008/10/16", "$470,600"],
["Haley Kennedy", "Senior Marketing Designer", "London", "3597", "2012/12/18", "$313,500"],
["Tatyana Fitzpatrick", "Regional Director", "London", "1965", "2010/03/17", "$385,750"],
["Michael Silva", "Marketing Designer", "London", "1581", "2012/11/27", "$198,500"],
["Paul Byrd", "Chief Financial Officer (CFO)", "New York", "3059", "2010/06/09", "$725,000"],
["Gloria Little", "Systems Administrator", "New York", "1721", "2009/04/10", "$237,500"],
["Bradley Greer", "Software Engineer", "London", "2558", "2012/10/13", "$132,000"],
["Dai Rios", "Personnel Lead", "Edinburgh", "2290", "2012/09/26", "$217,500"],
["Jenette Caldwell", "Development Lead", "New York", "1937", "2011/09/03", "$345,000"],
["Yuri Berry", "Chief Marketing Officer (CMO)", "New York", "6154", "2009/06/25", "$675,000"],
["Caesar Vance", "Pre-Sales Support", "New York", "8330", "2011/12/12", "$106,450"],
["Doris Wilder", "Sales Assistant", "Sidney", "3023", "2010/09/20", "$85,600"],
["Angelica Ramos", "Chief Executive Officer (CEO)", "London", "5797", "2009/10/09", "$1,200,000"],
["Gavin Joyce", "Developer", "Edinburgh", "8822", "2010/12/22", "$92,575"],
["Jennifer Chang", "Regional Director", "Singapore", "9239", "2010/11/14", "$357,650"],
["Brenden Wagner", "Software Engineer", "San Francisco", "1314", "2011/06/07", "$206,850"],
["Fiona Green", "Chief Operating Officer (COO)", "San Francisco", "2947", "2010/03/11", "$850,000"],
["Shou Itou", "Regional Marketing", "Tokyo", "8899", "2011/08/14", "$163,000"],
["Michelle House", "Integration Specialist", "Sidney", "2769", "2011/06/02", "$95,400"],
["Suki Burks", "Developer", "London", "6832", "2009/10/22", "$114,500"],
["Prescott Bartlett", "Technical Author", "London", "3606", "2011/05/07", "$145,000"],
["Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500"],
["Martena Mccray", "Post-Sales support", "Edinburgh", "8240", "2011/03/09", "$324,050"],
["Unity Butler", "Marketing Designer", "San Francisco", "5384", "2009/12/09", "$85,675"]
];
var columnDefs = [{
title: "Name"
}, {
title: "Position"
}, {
title: "Office"
}, {
title: "Extn."
}, {
title: "Start date"
}, {
title: "Salary"
}];
var searchResults;
searchResults = $('#example').DataTable({
"sPaginationType": "full_numbers",
data: dataSet,
columns: columnDefs,
dom: 'Bfrtip', // Needs button container
select: 'single',
responsive: true,
buttons: []
});
// Setting the required behaviour to this question.
document.getElementById("btnSetEmptyResults").onclick = function() {
searchResults.context[0].oLanguage.sEmptyTable = "No matching records found...";
searchResults.clear().draw();
};
});
table.dataTable tbody>tr.selected,
table.dataTable tbody>tr>.selected {
background-color: #A2D3F6;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.0.2/css/responsive.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.1.2/css/buttons.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.1.2/css/select.dataTables.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.1.2/js/dataTables.select.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.0.2/js/dataTables.responsive.min.js"></script>
<div class="container">
<button id="btnSetEmptyResults" class="dt-button" type="button">
Set empty results
</button>
<table cellpadding="0" cellspacing="0" border="0" class="dataTable table table-striped" id="example">
</table>
</div>
Update:
If you need to print back all the data, you need to use the rows.add(data) method where the data parameter is the previous data that you used to print in the datatable plugin initially. Then use the .draw() method again to render the table:
searchResults.rows.add(assetId).draw();
In this demo: After 2 seconds will print back all the data in the table after the cleaning the datatable.
$(function() {
var dataSet = [
["Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800"],
["Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750"],
["Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000"],
["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "6224", "2012/03/29", "$433,060"],
["Airi Satou", "Accountant", "Tokyo", "5407", "2008/11/28", "$162,700"],
["Brielle Williamson", "Integration Specialist", "New York", "4804", "2012/12/02", "$372,000"],
["Herrod Chandler", "Sales Assistant", "San Francisco", "9608", "2012/08/06", "$137,500"],
["Rhona Davidson", "Integration Specialist", "Tokyo", "6200", "2010/10/14", "$327,900"],
["Colleen Hurst", "Javascript Developer", "San Francisco", "2360", "2009/09/15", "$205,500"],
["Sonya Frost", "Software Engineer", "Edinburgh", "1667", "2008/12/13", "$103,600"],
["Jena Gaines", "Office Manager", "London", "3814", "2008/12/19", "$90,560"],
["Quinn Flynn", "Support Lead", "Edinburgh", "9497", "2013/03/03", "$342,000"],
["Charde Marshall", "Regional Director", "San Francisco", "6741", "2008/10/16", "$470,600"],
["Haley Kennedy", "Senior Marketing Designer", "London", "3597", "2012/12/18", "$313,500"],
["Tatyana Fitzpatrick", "Regional Director", "London", "1965", "2010/03/17", "$385,750"],
["Michael Silva", "Marketing Designer", "London", "1581", "2012/11/27", "$198,500"],
["Paul Byrd", "Chief Financial Officer (CFO)", "New York", "3059", "2010/06/09", "$725,000"],
["Gloria Little", "Systems Administrator", "New York", "1721", "2009/04/10", "$237,500"],
["Bradley Greer", "Software Engineer", "London", "2558", "2012/10/13", "$132,000"],
["Dai Rios", "Personnel Lead", "Edinburgh", "2290", "2012/09/26", "$217,500"],
["Jenette Caldwell", "Development Lead", "New York", "1937", "2011/09/03", "$345,000"],
["Yuri Berry", "Chief Marketing Officer (CMO)", "New York", "6154", "2009/06/25", "$675,000"],
["Caesar Vance", "Pre-Sales Support", "New York", "8330", "2011/12/12", "$106,450"],
["Doris Wilder", "Sales Assistant", "Sidney", "3023", "2010/09/20", "$85,600"],
["Angelica Ramos", "Chief Executive Officer (CEO)", "London", "5797", "2009/10/09", "$1,200,000"],
["Gavin Joyce", "Developer", "Edinburgh", "8822", "2010/12/22", "$92,575"],
["Jennifer Chang", "Regional Director", "Singapore", "9239", "2010/11/14", "$357,650"],
["Brenden Wagner", "Software Engineer", "San Francisco", "1314", "2011/06/07", "$206,850"],
["Fiona Green", "Chief Operating Officer (COO)", "San Francisco", "2947", "2010/03/11", "$850,000"],
["Shou Itou", "Regional Marketing", "Tokyo", "8899", "2011/08/14", "$163,000"],
["Michelle House", "Integration Specialist", "Sidney", "2769", "2011/06/02", "$95,400"],
["Suki Burks", "Developer", "London", "6832", "2009/10/22", "$114,500"],
["Prescott Bartlett", "Technical Author", "London", "3606", "2011/05/07", "$145,000"],
["Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500"],
["Martena Mccray", "Post-Sales support", "Edinburgh", "8240", "2011/03/09", "$324,050"],
["Unity Butler", "Marketing Designer", "San Francisco", "5384", "2009/12/09", "$85,675"]
];
var columnDefs = [{
title: "Name"
}, {
title: "Position"
}, {
title: "Office"
}, {
title: "Extn."
}, {
title: "Start date"
}, {
title: "Salary"
}];
var searchResults;
searchResults = $('#example').DataTable({
"sPaginationType": "full_numbers",
data: dataSet,
columns: columnDefs,
dom: 'Bfrtip', // Needs button container
select: 'single',
responsive: true,
buttons: []
});
// Setting the required behaviour to this question.
document.getElementById("btnSetEmptyResults").onclick = function() {
searchResults.context[0].oLanguage.sEmptyTable = "No matching records found...";
searchResults.clear().draw();
// Get back all the data after 2 seconds.
setTimeout(function() {
searchResults.rows.add(dataSet).draw();
}, 2000);
};
});
table.dataTable tbody>tr.selected,
table.dataTable tbody>tr>.selected {
background-color: #A2D3F6;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.0.2/css/responsive.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.1.2/css/buttons.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.1.2/css/select.dataTables.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.1.2/js/dataTables.select.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.0.2/js/dataTables.responsive.min.js"></script>
<div class="container">
<button id="btnSetEmptyResults" class="dt-button" type="button">
Set empty results
</button>
<table cellpadding="0" cellspacing="0" border="0" class="dataTable table table-striped" id="example">
</table>
</div>

accessing nested array in nested object in angular js

I am using angularjs 1.I have a pretty complex json object with a lot of nesting . I want to use ng-repeat on a json to access a nested array.
[{
"information": {
"name": "simdi jinkins",
"phone": "08037775692",
"email": "sim04ful#gmail",
"whatsapp": "8349493420",
"residential": "gwarinpa",
"office": "dansarari plaza"
},
"jobs": [{
"name": "jeans and shirt",
"measurement": {
"shoulder": "34",
"waist": "44",
"neck": "86",
"front": "42",
"length": "33",
"boost": "80",
"cap": "30",
"sleeves": "12",
"tommy": "30",
"thigh": "30",
"chest": "34",
"back": "40"
},
"account": {
"method": "cheque",
"amount": "2334",
"advance": "3945",
"date": "2016-07-22T09:54:06.395Z"
},
"date": {
"incharge": "2016-07-22T09:54:06.395Z",
"collection": "2016-07-22T09:54:06.395Z"
},
"style": "english",
"material": "our"
}, {
"name": "skirt and blouse",
"measurement": {
"shoulder": "35",
"waist": "45",
"neck": "85",
"front": "52",
"length": "53",
"boost": "85",
"cap": "50",
"sleeves": "52",
"tommy": "50",
"thigh": "35",
"chest": "35",
"back": "50"
},
"account": {
"method": "cheque",
"amount": "2334",
"advance": "5045",
"date": "2016-07-22T09:54:06.395Z"
},
"date": {
"incharge": "2016-07-22T09:54:06.395Z",
"collection": "2016-07-22T09:54:06.395Z"
},
"style": "native",
"material": "bought"
}]
}, {
"information": {
"name": "Paula Odama",
"phone": "08034698692",
"email": "paulyd#gmail",
"whatsapp": "8348733420",
"residential": "inpa",
"office": "dansaza"
},
"jobs": [{
"name": "gown",
"measurement": {
"shoulder": "74",
"waist": "44",
"neck": "76",
"front": "42",
"length": "73",
"boost": "80",
"cap": "37",
"sleeves": "72",
"tommy": "30",
"thigh": "70",
"chest": "37",
"back": "70"
},
"account": {
"method": "cheque",
"amount": "2334",
"advance": "3945",
"date": "2016-07-22T09:54:06.395Z"
},
"date": {
"incharge": "2016-07-22T09:54:06.395Z",
"collection": "2016-07-22T09:54:06.395Z"
},
"style": "english",
"material": "our"
}, {
"name": "robes",
"measurement": {
"shoulder": "35",
"waist": "45",
"neck": "85",
"front": "52",
"length": "53",
"boost": "85",
"cap": "50",
"sleeves": "52",
"tommy": "50",
"thigh": "35",
"chest": "35",
"back": "50"
},
"account": {
"method": "cheque",
"amount": "2334",
"advance": "5045",
"date": "2016-07-22T09:54:06.395Z"
},
"date": {
"incharge": "2016-07-22T09:54:06.395Z",
"collection": "2016-07-22T09:54:06.395Z"
},
"style": "native",
"material": "bought"
}]
}];
i am trying to access the name property in jobs i have tried the following
<div ng-repeat="customer in customers" class="card rich-card" z="2">
<div class="card-hero" style="">
<h1>{{customer.jobs.name}} <span>{{}}</span> </h1>
</div>
<div class="divider"></div>
<div class="card-footer">
<button class="button flat">View</button>
<button class="button flat color-orange-500">Explore</button>
</div>
</div>
Because customer.jobs is an array, you must access it using and index or key.
In your example, the way to do this would be using customer.jobs[0].name.
The resulting HTML would like this:
<div ng-repeat="customer in customers" class="card rich-card" z="2">
<div class="card-hero" style="">
<div data-ng-repeat="job in customer.jobs">
<h1>{{job.name}} <span>{{}}</span> </h1>
</div>
</div>
<div class="divider"></div>
<div class="card-footer">
<button class="button flat">View</button>
<button class="button flat color-orange-500">Explore</button>
</div>
</div>
UPDATE
It's an array of customers, with each containing an array of jobs. As such, you need a double repeater to cycle through the first AND second array.
UPDATE 2
I figured you might want a 'card' per job a customer has, that code would be as follows:
<div data-ng-repeat="customer in customers">
<div ng-repeat="job in customer.jobs" class="card rich-card" z="2">
<div class="card-hero" style="">
<h1>{{job.name}} <span>{{}}</span> </h1>
</div>
<div class="divider"></div>
<div class="card-footer">
<button class="button flat">View</button>
<button class="button flat color-orange-500">Explore</button>
</div>
</div>
</div>
You did not explicitly say that your array is called customers, so I am assuming that it is.
You have an array of customers, and each customer has one or more jobs. If you want to display the name of ALL jobs for each customer, you need to use nested ng-repeats. I'm not sure which part of your UI you want to repeat but I'm just going with the 'card-hero' div.
<div ng-repeat="customer in customers" class="card rich-card" z="2">
<h1>{{customer.information.name}}</h1>
<div ng-repeat="job in customer.jobs" class="card-hero" style="">
<h2>{{job.name}} <span>{{}}</span> </h2>
</div>
<div class="divider"></div>
<div class="card-footer">
<button class="button flat">View</button>
<button class="button flat color-orange-500">Explore</button>
</div>
</div>
EDIT: added h1 customer name, and changed job name to h2, to show that each job under each customer is displayed

Carousel in angular

A carousel say "Cr1" is displaying the category. I have another carousel beneath it say "Cr2" which is displaying the products based on the category clicked from "Cr1". The value for both are populated from a single JSON. Now my problem is I am unable to display the product in the "Cr2". Need help with that
/**
* Created by Sneha_Subhash on 6/10/2016.
*/
var myApp = angular.module('myApp', []);
myApp.controller("MasterDetailCtrl", function($scope, $http) {
$scope.categoryList = [{
"id": "1",
"name": "Banking",
"productList": [{
"productId": "x10001",
"productName": "Direct Deposit",
"categoryid": {
"id": "1",
"name": "banking"
},
"productURL": "http://bankonsanfrancisco.com/why",
"productDesc": "High drama ensued after the emergency landing of a Mangaluru-bound " +
"Jet Airways flight that took off from Kempegowda International Airport (KIA) on Wednesday morning. Fortunately, " +
"none of the passengers or crew members were injured. They were all evacuated to safety.The flight made an emergency" +
" landing at KIA 15 minutes after the take off after smoke was detected in the cabin and an engine caught up in flames. " +
"Jet Airways said that the flight then came back to KIA for an emergency landing. Soon after landing, the Aircraft Rescue and Fire-fighting Team at KIA rushed to the aircraft and evacuated all the 65 passengers and four crew members on board.Ajeet Khare, Managing Director, Canara Lightings, Mangaluru, was one of the passengers, who was flying with his wife.",
"createddate": "9\/18\/1996",
"updateddate": "9\/18\/2015",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [{
"link1": "img1",
"link2": "img2"
}],
"bgimage": "https://images.unsplash.com/photo-1462146449396-2d7d4ba877d7?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=c219903b4e38c5b8109e11a3d33b9748"
}, {
"productId": "x10002",
"productName": "Individual Banking",
"categoryid": {
"id": "1",
"name": "banking"
},
"productURL": "https://www.google.co.in/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&q=individual%20banking&oq=individual%20banking&aqs=chrome..69i57j0l5.4255j0j7",
"productDesc": "Short Desc",
"createddate": "9\/18\/1996",
"updateddate": "9\/18\/2015",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [{
"link1": "img1",
"link2": "img2"
}],
"bgimage": "https://images.unsplash.com/photo-1462726625343-6a2ab0b9f020?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=eb6506972ee7685166b2d8b649d29a1b"
}, {
"productId": "x10003",
"productName": "Business Banking",
"categoryid": {
"id": "1",
"name": "banking"
},
"productURL": "http://bankonsanfrancisco.com/why",
"productDesc": "Short Desc",
"createddate": "9\/18\/1996",
"updateddate": "9\/18\/2015",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [{
"link1": "img1",
"link2": "img2"
}],
"bgimage": "https://images.unsplash.com/photo-1462910211773-a9847b1f0e40?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=600fdca8f6340569864d4f94f5f9dfc1"
}, {
"productId": "x10004",
"productName": "Digital Banking",
"categoryid": {
"id": "1",
"name": "banking"
},
"productURL": "https://localfirstbank.com/business/",
"productDesc": "Online banking, also known as internet banking, e-banking or virtual banking, is an electronic payment system that enables customers of a bank or other financial institution to conduct a range of financial transactions through the financial institution's website. The online banking system will typically connect to or be part of the core banking system operated by a bank and is in contrast to branch banking which was the traditional way customers accessed banking services. Fundamentally and in mechanism, online banking, internet banking and e-banking are the same thing.",
"createddate": "9\/20\/1996",
"updateddate": "1\/20\/2015",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [{
"link1": "img1",
"link2": "img2"
}],
"bgimage": "https://images.unsplash.com/photo-1464054313797-e27fb58e90a9?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=576bb45620043f729baef96301c9acb6"
}]
}, {
"id": "2",
"name": "Insurance",
"productList": [{
"productId": "x10005",
"productName": "Embee Ins. Brokers Ltd.",
"categoryid": {
"id": "2",
"name": "Insurance"
},
"productURL": "http://www.embeegroup.in/",
"productDesc": "Embee Financial Services Ltd. is an integrated 'Niche' financial services group that provides full range of corporate advisory services to its clients. The services provided include one stop solution to the Corporate & SMEs in areas of Corporate Finance & Investment Banking, Management Consulting, Wealth Management, Legal & Statutory services & Insurance Broking.",
"createddate": "9\/20\/1896",
"updateddate": "1\/20\/2014",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [{
"link1": "img1",
"link2": "img2"
}],
"bgimage": "https://images.unsplash.com/photo-1464400694175-33544b41703d?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=680f4a54596d9fa9f20a029e297b1360"
}, {
"productId": "x10006",
"productName": "Excellent Insurance Broking Services Ltd.",
"categoryid": {
"id": "2",
"name": "Insurance"
},
"productURL": "http://www.excellentinsurancebroking.com/",
"productDesc": "Excellent Insurance Broking Services Ltd is one of the leading insurance broking firms that operate on both direct and reinsurance broking licenced & regulated by IRDAI. Backed by more than a decade of experience and a team of highly qualifiedand professionals from Insurance, Reinsurance, Engineering, Finance, Medicine, IT,Legal and Investigation fields. We are based in Hyderabad, India, with a branch in Bangalore is positioned to handle all insurance and reinsurance requirements through exclusive networks of national and international associates and underwriters. We give innovative solutions with highest competence. EIBSL works closely with insurers to negotiate competitive rates to meet the needs of both existing and potential clients.",
"createddate": "9\/20\/1996",
"updateddate": "1\/20\/2015",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [{
"link1": "img1",
"link2": "img2"
}],
"bgimage": "https://images.unsplash.com/photo-1465152251391-e94453ee3f5a?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=2f3699fc4dbc682fbecdc4fa4d5f6cad"
}]
}, {
"id": "3",
"name": "Automobile",
"productList": [{
"productId": "x10007",
"productName": "Ford Model T",
"categoryid": {
"id": "3",
"name": "Automobile"
},
"productURL": "https://en.wikipedia.org/wiki/Ford_Model_T",
"productDesc": "The first car to achieve one million, five million, ten million and fifteen million units sold. By 1914, it was estimated that nine out of every ten cars in the world were Fords",
"createddate": "9\/20\/1908",
"updateddate": "1\/20\/2015",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [{
"link1": "img1",
"link2": "img2"
}],
"bgimage": "http:\/\/www.pmbl-ng.com\/images\/about.jpg"
}, {
"productId": "x10008",
"productName": "Volkswagen Beetle",
"categoryid": {
"id": "3",
"name": "Automobile"
},
"productURL": "https://en.wikipedia.org/wiki/Volkswagen_Beetle",
"productDesc": "The need for this kind of car, and its functional objectives, were formulated by Joseph Ganz, an engineer whose ideas influenced Adolf Hitler after he saw the car at an auto show. The leader of Nazi Germany wished for a cheap, simple car to be mass-produced for the new road network of his country. He contracted Ferdinand Porsche in 1934 to design and build it, after telling him in 1933 ",
"createddate": "9\/20\/1938",
"updateddate": "1\/20\/2015",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [{
"link1": "http://images.unsplash.com/photo-1454447170982-596ddff4606a?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=98aa2bb815b9839f16822ecdd38e28ae",
"link2": "http://images.unsplash.com/photo-1452215199360-c16ba37005fe?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=408c70a6e88b50949c51e26424ff64f3"
}],
"bgimage": "http://images.unsplash.com/photo-1459902552792-28b7925b06c2?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=999e6d0ae0e189e1959b31677f5a9848"
}, {
"productId": "x10009",
"productName": "Toyota Corolla",
"categoryid": {
"id": "3",
"name": "Automobile"
},
"productURL": "https://en.wikipedia.org/wiki/Toyota_Corolla",
"productDesc": "The Toyota Corolla is a line of subcompact and compact cars manufactured by Toyota. Introduced in 1966, the Corolla was the best-selling car worldwide by 1974[1] and has been one of the best-selling cars in the world since then. In 1997, the Corolla became the best selling nameplate in the world, surpassing the Volkswagen Beetle.[2] Toyota reached the milestone of 40 million Corollas sold over eleven generations in July 2013.[3] The series has undergone several major redesigns. The name Corolla is part of Toyota's naming tradition of using names derived from the Toyota Crown for sedans. The Corolla has always been exclusive in Japan to Toyota Corolla Store locations, and manufactured in Japan with a twin, called the Toyota Sprinter until 2000. In Japan and much of the world, the hatchback companion since 2006 is called the Toyota Auris. Prior to the Auris, Toyota used the Corolla name on the hatchback bodystyle in various international markets.",
"createddate": "9\/20\/1966",
"updateddate": "1\/20\/2015",
"documents": [{
"link1": "url1",
"link2": "url2",
"link3": "url3"
}],
"videos": [{
"link1": "url1",
"link2": "url2"
}],
"screenshot": [
"http://images.unsplash.com/photo-1427464407917-c817c9a0a6f6?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=812662922febc6b1006719224d6c3772",
"http://images.unsplash.com/photo-1452215199360-c16ba37005fe?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=408c70a6e88b50949c51e26424ff64f3"
],
"bgimage": "http://images.unsplash.com/photo-1436262513933-a0b06755c784?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=0b6cf0f2bd64f9788f12b2b43c959c11"
}]
}
];
$scope.selectedProduct = $scope.categoryList[0].productList[0].productId;
// $scope.productId = $scope.selectedProduct.productId;
$scope.selectedCategory = $scope.categoryList[0].id;
$scope.selectProduct = function(val) {
//$scope.selectedProduct = val;
$scope.selectedCategory = val;
$scope.loadProducts();
}
$scope.loadProducts = function() {
$scope.listOfProducts = null;
// $scope.listOfProducts = $scope.selectedProduct;
$scope.listOfProducts = $scope.selectedCategory;
}
});
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="carousel.js"></script>
<style>
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 100%;
margin: auto;
}
.carousel-inner{
height: 500px;
}
/* .scrolls {
overflow-x: scroll;
overflow-y: hidden;
height: 80px;
white-space:nowrap
}*/
</style>
</head>
<body ng-controller="MasterDetailCtrl" class="w3-container">
<div class="container">
<br>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="images/vase.jpg" alt="Chania" width="460" height="300">
<div class="carousel-caption">
<h3>Vase</h3>
<p>The atmosphere in Chania has a touch of Florence and Venice.</p>
</div>
</div>
<div class="item">
<img src="images/shell.jpg" alt="Chania" width="460" height="300">
<div class="carousel-caption">
<h3>Sea Shell</h3>
<p>The atmosphere in Chania has a touch of Florence and Venice.</p>
</div>
</div>
<div class="item">
<img src="images/turtle.jpg" alt="Flower" width="460" height="300">
<div class="carousel-caption">
<h3>Turtle</h3>
<p>The atmosphere in Chania has a touch of Florence and Venice.</p>
</div>
</div>
<div class="item">
<img src="images/elephant.jpg" alt="Flower" width="460" height="300">
<div class="carousel-caption">
<h3>Elephant</h3>
<p>The atmosphere in Chania has a touch of Florence and Venice.</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<div class="well text-center">
Purposeful AI, when applied to the enterprise, can unlock human potential and amplify people’s ability to do more. To realize this, organizations need to be able to do three things: manage organizational knowledge, apply it to automate enterprise processes, and utilize the massive intelligence hidden away in systems, machines and people.
Infosys Mana is a knowledge-based AI platform. It brings machine learning together with the deep knowledge of an organization to drive automation and innovation. This enables businesses to continuously reinvent their system landscapes. Mana, with the Infosys AiKiDo service offerings, dramatically lowers the cost of maintenance for both physical and digital assets. It captures the knowledge and know-how of people across fragmented and complex systems, and simplifies the continuous renovation of core business processes. Mana also enables businesses to bring new, delightful user experiences leveraging state-of-the-art technology.
</div>
<div class="well">
<header>
<ul class="nav nav-pills nav-justified scrolls">
<li data-target="#myCarousel" data-slide-to="0" class="active">
About<small>Lorem ipsum dolor sit</small>
</li>
<li ng-repeat="category in categoryList"><a href="#"><i class="fa fa-home" ng-click="selectproduct(category);"></i>
{{category.name}}</a>
</li>
</ul>
</header>
<div class = "well" id ="productDetails">
<div class="productCard">
<div class="w3-card-4" style="width:30%;" ng-repeat="product in categoryList.productList"-->
<header class="w3-container w3-blue">
<h1>Header{{product.productName}}</h1>
</header>
<div class="w3-container">
<p>{{product.productDesc}}</p>
<p><button class="w3-btn w3-dark-grey">Button</button></p>
</div>
<footer class="w3-container w3-blue">
<h5> <a ng-href="{{selectedProduct.productURL}}">{{selectedProduct.productURL}}</a></h5>
</footer>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
check this , your question is unclear , in this fix the carousel please check
https://plnkr.co/edit/tJKid1pCREnRP9iMvP2n?p=preview
add your css
.carousel-caption {
position: inherit !important;
right: 0 !important;
bottom: 0 !important;
left: 0 !important;
}

bootstrap carousel does not work with handelbars (prev button )

I'm using bootstrap v3
the process works fine without using js template , once I'm using handelbars , the previous button will crash and throw error ( Uncaught TypeError: Cannot read property 'slice' of undefined ) with index position is 0 I guess
the problem occur while transition from the first element to the last element using previous button of course , the 'active class is lost somewhere'
could anyone help
here is my html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
</head>
<body>
<div id="carouselWrap" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carouselWrap" data-slide-to="0" class="active"></li>
<li data-target="#carouselWrap" data-slide-to="1"></li>
<li data-target="#carouselWrap" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<script id="template" type="text/x-handlebars-template">
{{#each this}}
{{#if counter}}
<div class="item active">
{{else}}
<div class="item ">
{{/if}}
<table>
<tbody>
<tr>
<td> {{product1.name}} {{decode product1.surname}}</td>
<td>{{price product1.lastprice}} </td>
<td>{{decodeproduct1.supplier}} </td>
<td>{{product1.nation}} </td>
<td>{{product1.sport}} </td>
<td>{{product1.divStart}} - {{product1.divEnd}} </td>
<td>{{{decode product1.divScenarioGood}}}</td>
<td>link</td>
</tr>
<tr>
<td>{{product2.name}} {{decode product2.surname}}</td>
<td>{{price product2.lastprice}} </td>
<td>{{decode product2.supplier}} </td>
<td>{{product2.nation}} </td>
<td>{{product2.sport}} </td>
<td>{{product2.divStart}} - {{product1.divEnd}} </td>
<td>{{decode product2.divScenarioGood}}</td>
<td>link</td>
</tr>
</tbody>
</table>
</div>
{{/each}}
</script>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carouselWrap" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carouselWrap" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script>
(function() {
var Hbs = {
init: function( config ) {
this.url = config.url;
this.container = config.container;
this.template = config.template;
this.fetch();
},
fetch: function() {
var self = this;
$.getJSON( self.url, function( data ) {
var template = Handlebars.compile( self.template );
Handlebars.registerHelper('toLowerCase', function(str) {
return str.toLowerCase();
});
Handlebars.registerHelper('price', function(val) {
return Math.round(val);
});
Handlebars.registerHelper('elmId', function(id) {
return id;
});
Handlebars.registerHelper('decode', function(str) {
try{
return decodeURIComponent(escape(str));
}catch(e){
// catch the error
console.log(e.message);
}
});
var positionCounter = 0;
Handlebars.registerHelper('counter', function() {
positionCounter++;
if (positionCounter == 1 )
return positionCounter;
else
return false;
});
self.container.append( template( data ) );
});
}
}
Hbs.init({
url : 'athletes.json',
container: $('.carousel-inner'),
template: $('#template').html()
});
})();
</script>
</body>
</html>
athletes.json
[
{
"#class": "com.tradeinsports.domain.product.ProductPair",
"product1": {
"#class": "com.tradeinsports.domain.product.ProductSubset",
"name": "Alexander",
"surname": "Bj\u00c3\u00b6rk",
"shortname": "A Bj\u00c3\u00b6rk",
"sport": "Golf",
"nation": "Sweden",
"supplier": "V\u00c3\u00a4xj\u00c3\u00b6 GK",
"status": "Locked",
"lastprice": 50.497987979,
"divStart": "2012-07-19",
"divEnd": "2013-12-25",
"contractType": "Travprodukt standard",
"divScenarioGood": "Topp 10 p\u00c3\u00a5 European tour 2016\r\n",
"divScenarioGoodRevenue": -10000,
"smallImage": "litenNyBjork.jpg"
},
"product2": {
"#class": "com.tradeinsports.domain.product.ProductSubset",
"name": "Felix",
"surname": "Rosenqvist",
"shortname": "F Rosenqvist",
"sport": "Motor",
"nation": "Sweden",
"supplier": "Mercedes",
"status": "Locked",
"lastprice": 100,
"divStart": "2012-12-29",
"divEnd": "2021-02-24",
"contractType": "Motor standard",
"divScenarioGood": "4 s\u00c3\u00a4songer i Formel 1 fram till 2021\r\n",
"divScenarioGoodRevenue": 12960,
"smallImage": "FelixFarg.jpg"
}
},
{
"#class": "com.tradeinsports.domain.product.ProductPair",
"product1": {
"#class": "com.tradeinsports.domain.product.ProductSubset",
"name": "sabri",
"surname": "zouari",
"shortname": "Wild Life",
"sport": "Trotting",
"nation": "Sweden",
"supplier": "R Bj\u00c3\u00b6rkroth",
"status": "Locked",
"lastprice": 200,
"divStart": "2014-04-16",
"divEnd": "2016-05-14",
"contractType": "Travprodukt standard",
"divScenarioGood": "2.000.000 i insprugna prispengar + 5.000.000 fr\u00c3\u00a5n f\u00c3\u00b6rs\u00c3\u00a4ljning\r\n",
"divScenarioGoodRevenue": 27900,
"smallImage": "wildLifeProd2.jpg"
},
"product2": {
"#class": "com.tradeinsports.domain.product.ProductSubset",
"name": "Rasmus",
"surname": "Lindh",
"shortname": "R Lindh",
"sport": "Motor",
"nation": "Sweden",
"supplier": "Captimax",
"status": "Locked",
"lastprice": 100,
"divStart": "2019-01-01",
"divEnd": "2029-12-15",
"contractType": "Motor Total",
"divScenarioGood": "10 s\u00c3\u00a4songer i Formel 1 fram till 2029\r\n",
"divScenarioGoodRevenue": 4840,
"smallImage": "rasmusSmallSyst.jpg"
}
},
{
"#class": "com.tradeinsports.domain.product.ProductPair",
"product1": {
"#class": "com.tradeinsports.domain.product.ProductSubset",
"name": "Andreas",
"surname": "Siljestr\u00c3\u00b6m",
"shortname": "A Siljestr\u00c3\u00b6m",
"sport": "Tennis",
"nation": "Sweden",
"supplier": "KLTK",
"status": "Market",
"lastprice": 100,
"divStart": "2013-12-01",
"divEnd": "2016-12-01",
"contractType": "Tennis",
"divScenarioGood": "Topp 10 ATP dubbelranking 2016\r\n",
"divScenarioGoodRevenue": 1050,
"smallImage": "siljestromLiten.jpg"
},
"product2": {
"#class": "com.tradeinsports.domain.product.ProductSubset",
"name": "Gabriel",
"surname": "Axell",
"shortname": "G Axell",
"sport": "Golf",
"nation": "Sweden",
"supplier": "Vadstena GK",
"status": "Market",
"lastprice": 100,
"divStart": "2014-04-15",
"divEnd": "2018-04-15",
"contractType": "Travprodukt standard",
"divScenarioGood": "Topp 10 p\u00c3\u00a5 Europatouren 2017",
"divScenarioGoodRevenue": 1990,
"smallImage": "litenGabbeSyst.jpg"
}
}
]
I have had the same problem with Django template system but i solved rewriting the if statement like this (assuming that counter starts in 1)
{{#if counter = 1}}
<div class="item active">
{{else}}
<div class="item ">
{{/if}}
I had the same problem and did looking for solution several hour, but it was ... little mistake - my controls was in div class="item" inside.))) Be sure that controls are outside couresel's item

Categories

Resources