Ways to showcase Firebase information with multi-tiered keys in an HTML table?

I am struggling to showcase information from a Firebase database with a multi-level key onto an HTML table using Angular.

Here is the structure of the data:

https://i.sstatic.net/qQ6RZ.jpg https://i.sstatic.net/PIaUZ.jpg

When attempting to display using ng-view, the outcome looks like this:

My Controller:

.controller('SalesCtrl', ['$scope', '$firebaseArray', '$firebaseObject', function($scope, $firebaseArray, $firebaseObject) {

    console.log('Sales Controller loaded..');
    var ref = firebase.database().ref("pelanggan/sales01");

    var list = $firebaseObject(ref);

    list.$loaded().then(function() {
        $scope.list = [];
        angular.forEach(list, function(value,key){
            $scope.list.push({ id: key, data: value})
        });
    });

I have experimented with different approaches like using ng-repeat and ng-repeat-start. However, I'm puzzled by why I am getting JSON format in my table.

My aim is to present the data in a format similar to the following:

-------------------------------------------------------------
| address             | email             | identity           | service     |
-------------------------------------------------------------
| jl.prapanca...      | <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="423a3a02272f232b2e6c212d2f">[email protected]</a> | 12345          | xxxxxxxx |
-------------------------------------------------------------

Answer №1

In my experience, using ng-repeat-start and ng-repeat-end in certain situations may not be the most suitable approach. When working with HTML tables, a simpler ng-repeat setup is often more effective.

<table>
  <thead>
    <tr>
      <td>alamat</td>
      <td>email</td>
      <td>identitas</td>
      <td>layanan</td>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="item in list">
      <td>{{item.alamat}}</td>
      <td>{{item.email}}</td>
      <td>{{item.identitas}}</td>
      <td>{{item.layanan}}</td>
    </tr>
  </tbody>
</table>

Referencing the Angular documentation for ng-repeat, it is clear that while ng-repeat-start and ng-repeat-end can be utilized for special cases in tables, they are more suited for <div> elements.

With data in JSON format, you can easily access and display the necessary properties manually.

If a dynamically rendered table is your goal, achieving an 'elegant' solution might prove challenging. Depending on your project requirements, opting for a straightforward ng-repeat setup could be the most straightforward approach.

Answer №2

Here is my solution to the problem.

After making changes in my Controller:

var reference = firebase.database().ref().child("customer").child("sales01");
$scope.sales = $firebaseArray(reference); 
var data = $firebaseArray(reference); 
$scope.info = $scope.sales 
console.log("info: "+data.length);

And in the view:

<div class="row" ng-controller="SalesCtrl">
<!-- <div class="row" ng-controller="singleCustomerController"> -->

<div class="col-md-5" ng-show="addSalesFormShow">
    <h3>Add Sales</h3>
    <form ng-submit="addSales()">
      <div class="form-group">
        <label>Address</label>
        <input type="text" class="form-control" ng-model="address" placeholder="Address" required="">
      </div>

      <div class="form-group">
        <label>Email</label>
        <input type="email" class="form-control" ng-model="email" placeholder="Email" required="">
      </div>

      <div class="form-group">
        <label>Identity</label>
        <input type="text" class="form-control" ng-model="identity" placeholder="Identity" required="">
      </div>

      <div class="form-group">
        <label>lo</label>
        <input type="text" class="form-control" ng-model="lo" placeholder="lo" required="">
      </div>

      <div class="form-group">
        <label>lt</label>
        <input type="text" class="form-control" ng-model="lt" placeholder="lt" required="">
      </div>

      <div class="form-group">
        <label>Name</label>
        <input type="text" class="form-control" ng-model="name" placeholder="Name" required="">
      </div>

      <button type="submit" class="btn btn-success">Submit</button>
      <!-- <button type="cancel" class="btn btn-default" onclick='resetForm()'>Cancel</button> -->
    </form>
</div>

<div class="col-md-5" ng-show="editSalesFormShow">
    <h3>Edit Sales</h3>
    <form ng-submit="editSales()">
      <div class="form-group">
        <label>Address</label>
        <input type="text" class="form-control" ng-model="address" placeholder="Address" required="">
      </div>

      <div class="form-group">
        <label>Email</label>
        <input type="email" class="form-control" ng-model="email" placeholder="Email" required="">
      </div>

      <div class="form-group">
        <label>lo</label>
        <input type="text" class="form-control" ng-model="lo" placeholder="lo" required="">
      </div>

      <div class="form-group">
        <label>lt</label>
        <input type="text" class="form-control" ng-model="lt" placeholder="lt" required="">
      </div>

      <div class="form-group">
        <label>Name</label>
        <input type="text" class="form-control" ng-model="name" placeholder="Name" required="">
      </div>

      <div class="form-group">
        <label>Phone Number</label>
        <input type="text" class="form-control" ng-model="phone" placeholder="Phone" required="">
      </div>

      <button type="submit" class="btn btn-success">Submit</button>
      <button type="cancel" class="btn btn-danger">Cancel</button>
    </form>
</div>

<div class="col-md-7">
    <h3>Sales Information</h3>

    <table class="table table-striped hoverTable" data-ng-controller="SalesCtrl">
        <thead>
            <tr>
                <th>Address</th>
                <th>Email</th>
                <th>Identity</th>
                <th>lo</th>
                <th>lt</th>
                <th>Name</th>
                <th>Phone</th>
                <th></th>
            </tr>   
        </thead>
        <tbody data-ng-repeat="sales in sales">
             <tr>
                <td>{{sales.address}}</td>
                <td>{{sales.email}}</td>
                <td>{{sales.identity}}</td>
                <td>{{sales.lo}}</td>
                <td>{{sales.lt}}</td>
                <td>{{sales.name}}</td>
                <td>{{sales.phone}}</td>
                <td><a class="btn btn-success" ng-click="showEditSalesForm(sales)">Edit</a></td>
            <td><a class="btn btn-danger" ng-click="removeSales(sales)">Delete</a></td>
             </tr>
        </tbody>
    </table>
</div>

</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Learn how to implement Redux login to display the first letter of a user's name and their login name simultaneously

I am implementing a Redux login feature and after successful login, I want to display the first letter of the user's name or email in a span element within the header section. Can anyone provide a solution for this? Below is my Redux login code snippe ...

Enhancing Rails: Tailoring the flash message to suit individual needs

I am embarking on my journey with ruby on rails and could use some guidance with the following scenario. In the application.html.erb file, flash messages are configured to fade out after a few seconds by default. <div id="message" class="modal alert a ...

Error encountered in React while using an object in useState: TypeError - Unable to access property 'name' of undefined

Encountering an issue with receiving JSON data from a route. When logging the data, it shows up correctly. However, when passing it to setProfileData(data), the updated state becomes undefined. Interestingly, when using setProfileData(data.user.name), it ...

What is the best way to apply "display: none;" on a span element nested within a title attribute?

I am utilizing the social-share-button gem to share blog posts on social media. The website has been internationalized, making it bilingual (English and German). Everything is functioning correctly, but I encounter an issue with the social share buttons wh ...

Utilizing the JavaScript map method to structure API response data

Here is the JSON data I have: { "result": [{ "name": "a", "value": 20, "max": 100, "sale_value": [{ "no": 1, "name": "aaaaa", "price": 200 }, { "no": 2, ...

Discovering the method for accessing nested JSON data through ng-repeat in AngularJS

I'm attempting to access the items._id value within ng-view using ng-repeat. I am able to retrieve all data, but I am interested in specific data only. Data.json [ { _id : "td6v9db4514cc4ewew4334", firstName : 'ayaz', la ...

Change the background color of the MUI ToggleButton that is currently selected

I need help figuring out how to change the background color of a selected toggle button. Currently, the buttons are functional but do not visually indicate when one is selected. I would like the first button (Btn 1) to have a default color, and if the us ...

Dealing with errors in React by utilizing the setState function

Encountering an issue while trying to update the state of a single component. A warning message states: Each child in an array or iterator should have a unique "key" prop. The list was created within the state. The intention is to update the list upon c ...

What is the process for requesting a specific condition using jscript and jquery?

I'm experimenting with the following code: while (true) { $(document).ready(function() { setInterval(function () { if ($("h2").text() == "What is a light-year?") { $("#choice2").delay(200).queue ...

What is the best way to manage classNames dynamically in React with Material-UI?

I am wondering how to dynamically add and remove classes from an img tag. My goal is to change the image automatically every 2 seconds, similar to Instagram's signup page. I am struggling to achieve this using the material-ui approach. Below is a snip ...

Regularly switch up the background image using the same URL

I am currently developing an angular JS application where the background of my body needs to change every minute based on the image stored on my server. In my HTML file, I am using ng-style to dynamically set the background image: <body ng-controller= ...

Utilizing nested styling with material-ui v1's withStyles feature

Currently, I am working on building a React component using separate major containers as React class components. While I understand how to use withStyles with a single component, I am a bit confused when it comes to applying styles to more than two compone ...

unable to transfer Vuex store information to the graph

Currently, I am facing an issue with passing my vuex store data into my apexcharts graph. Despite my efforts, it seems like the data is not being displayed correctly. Can anyone provide guidance on what I might be doing wrong? My main objective is to updat ...

Unable to retrieve post information from Angular using PHP

I've hit a roadblock in my Angular App where I can't seem to access the body of the post data being sent from Angular 4. Despite numerous attempts, I'm unable to retrieve this crucial information. Can anyone lend a hand in identifying the is ...

What method is the most effective for retrieving the prior slug name in NextJS?

Looking for Help with Retrieving postID? Greetings! I am currently working on a basic post detail page using NextJS. My URL structure is: [postID]/[title].tsx On the post detail page, I need to fetch the post's data based on the postID, which is hig ...

The issue with jqTransform not displaying the select box value on a hidden contact form

Could really use some assistance here and apologize if it's a hassle: Link to contact form To view the contact form, simply click the "Contact" button in the top left corner. The jqTransform jQuery plugin is being used to style it. Initially, it&apo ...

The Vue mixin properties are devoid of content and lack reactivity

Could you please guide me in the right direction if this question has already been asked before? I really hope it's not a duplicate. I have a Vue application that is compiled using Webpack@NPM. In order to pass a property (roles) across all component ...

The initial item in a pagination/list is double-parsed on an AJAX website using Selenium 3.0.2, Firefox webdriver, and BeautifulSoup 4.5.1

For the past three days, I've been facing a frustrating issue with both Selenium and Bs4. While I suspect Selenium (or my code) to be the culprit. Like many others before me, I'm attempting to scrape data from this website: I'm moving from ...

specialized html elements within data-ng-options

I have a code snippet where I am populating select options from a controller using data-ng-options. However, I would also like to include an icon with each option. For example, I want to append <span class="fa fa-plus"></span> at the end of e ...

Retrieving the data from a Material UI Slider control

I'm encountering an issue with retrieving the value property I assigned to a component. event.target.value is returning undefined. How can I successfully access the value of the component? My goal is for handlePlayersChange() to be able to handle dyn ...