Utilizing Smart Table for Data Binding with JSON Dataset

I need help binding a JSON file to a smart table. How can I use the loop function for iteration? The design of the smart table is displaying, but the data from the JSON file is not binding.

Here is the JSON file:

[
{
        "year": 2013, 
        "id": "", 
        "doctor": "Dr. Smith", 
        "illness": "Flu", 
        "apptdate": "3/12/2013",
"details":"Patient had flu for 5 days. No medicines prescribed"
}
]

I am trying to retrieve the data using:

@Injectable()
export class SmartTablesService {
  constructor(private http: Http) {
    
        }
        smartTableData = [];
loadData() {
  console.log('loadData');
   this.http.get('http://192.168.0.100:8000/medical')

.subscribe((data) => {
          setTimeout(() => {
              var contactData = [];
              $.each(data.json(), function (key, value) {
                  var tempData = value.source;
                  contactData.push(tempData);
              });
              this.smartTableData = contactData;
          }, 1000);
      });
}
getData(): Promise<any> {
  console.log("Promise");
  this.loadData();
  return new Promise((resolve, reject) => {
      setTimeout(() => {
          console.log(this.smartTableData);
          resolve(this.smartTableData);
      }, 3000);
  });
}
}

    constructor(private http: Http) { }
       getComments() {
        
       return this.http.get('http://192.168.0.100:8000/article' )
          .map((res: Response) => res.json())
          .catch((error:any) => Observable.throw(error));
       }
}

This is the component section:

@Component({
  selector: 'new',
  template: '<ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>'
})
export class NewComponent {
    query: string = '';
    
      settings = {
        noDataMessage: 'Loading...',
       columns: {
        year: {
            title: 'YEAR',
            type: 'string'
          },
          id: {
            title: 'ID',
            type: 'string'
          },
          doctor: {
            title: 'DOCTOR',
            type: 'string'
          },
          illness: {
            title: 'ILLNESS',
            type: 'string'
          },
          apptdate: {
            title: 'APPTDATE',
            type: 'string'
          },
          details: {
            title: 'DETAILS',
            type: 'string'
          }
      }
      };
    
// data

source: LocalDataSource = new LocalDataSource();
constructor(protected service: SmartTablesService){
  this.service.getData().then((data) => {
    this.source.load(data);
  });
}  
}

If anyone knows how to bind it, please help!

Answer №1

Make a simple adjustment to the subscription section on the service page to

var updatedData = value;

thus, .subscriber will appear as

.subscribe((data) => {
          setTimeout(() => {
              var contactInfo = [];
              $.each(data.json(), function (key, value) {
                  var updatedData = value;
                  contactInfo.push(updatedData);
              });
              this.smartTableData = contactInfo;
          }, 1000);
      });
}

This method is successful..!

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

Middleware in Express can be executed more than once

I am encountering a frustrating issue where my middlewares are being called multiple times without explanation. Despite having written short and simple code while learning Express and Node, I cannot pinpoint the reason for this behavior. I find it confusin ...

Issue with displaying options in Angular2 v2.4.9 HTML select element

Ever since I made the transition from AngularJS to Angular2, I've been facing a peculiar issue. The select element's options data is fetched from a Solr query, which always returns a 200 response with the data in a timely manner. However, the pr ...

Jasmine encountered an error while trying to compare the same string: 'Expected the values to match.'

I'm encountering an error message, despite verifying that the strings are identical: Expected { $$state : { status : 1, value : { customerNumber : 'customerNumber', name : 'name', userId : 'buId', customerType : 'ty ...

Fill the angular ui-bootstrap popover with content

Can anyone help me with populating an angular ui bootstrap popover? My goal is to populate the popover with a collection of actor names. Below is the code snippet: <div class="container" ng-if="radioModel=='Search for Actor'"> <p> ...

Using jQuery to store the name of a Div in a variable and subsequently invoking it in a function

Recently, I've been grappling with a task involving storing a div name in a variable for easier editing and incorporating it into standard actions like show/hide. My code functions perfectly without the variables, but introducing them causes the div ...

What are your thoughts on combining a JSON object with HTML?

When using ASP.NET MVC, it is possible to return a JSONResult. return JSON(new { View = RenderViewAsString("MyView", model), wasSuccessful = true}) This approach combines HTML and data in a single JSON object. The goal is to utilize strongly typed HtmlHe ...

Maintain the tab order for elements even when they are hidden

Check out this demonstration: http://jsfiddle.net/gLq2b/ <input value="0" /> <input id="test" value="1" /> <input value="2" /> By pressing the TAB key, it will cycle through the inputs in order. If an input is hidden when focused, press ...

Tips for personalizing the color scheme of Material UI Stepper Step?

I need help customizing the disabled Step color for Material UI Steppers. The default colors are Blue for enabled steps and Grey for disabled steps, but I want to change it to a different color as shown in this example: https://i.stack.imgur.com/HGGxp.png ...

Basic node.js server that responds with HTML and CSS

I have successfully created a basic http server to send an HTML file as a response. However, I'm struggling with how to also send a CSS file so that the client can view the HTML page styled with CSS in their browser. Here is my current code: var htt ...

I am having trouble getting Vue.js to function properly within HTML when using Django. Can someone please lend me a

The code run Here is the HTML document: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Register</title> <!--javascript extensions--> <script src=' ...

Using app.js in a blade file can cause jQuery functions and libraries to malfunction

In my Laravel application, I am facing an issue with my vue.js component of Pusher notification system and the installation of tinymce for blog posts. Adding js/app.js in my main layout blade file causes my tinymce and other jQuery functions to stop workin ...

Navigating JSON in a JAX-RS Client

Encountering an issue with the JAX-RS Client when attempting to test JSON data exchange. Using Jersey 2.10, JDK 1.7, Tomcat 7.0. Seeking advice on necessary steps and examples to resolve this issue. Currently lacking ContextResolver, Provider, MessageBodyW ...

JavaScript Enigma: Instantiate 2 Date variables with identical values, yet they ultimately display distinct dates on the calendar

I need some help understanding something in my screenshot. Although both tmpStart and itemDate have been assigned the same numeric value, they display different calendar dates. start = 1490683782833 -> tmpStart = "Sun Mar 26 2017 16:51:55 GMT+ ...

Troubleshooting JavaScript directly on the client side

As a JavaScript beginner hoping to transform into a JavaScript expert, debugging is an essential skill I must master. Currently, I am utilizing Chrome debugger tools to tackle a complex array of spaghetti JavaScript code that resembles a cryptic puzzle wai ...

Leveraging getScript to extract JSON data from a different domain

I've successfully implemented a local script that retrieves data from a JSON file: $.getJSON("jsonfile.js",function(item) { $.each(item.terra_nova_feed, function(i,item) { // functions and variables// }); }); However, when the JSON file ...

Search in the Firestore database for documents that have a field containing a reference to another document. Once those results are found, use the reference to conduct a second query

In an attempt to optimize the query that delivers details of all events a participant has attended, I have restructured my database schema. Events with participants are now linked through a subEvent subcollection in the users collection, storing document r ...

Is there Polyfill Compatibility for Custom Elements in Angular 9?

When it comes to polyfilling support for custom elements created with Angular, there are various recommendations available. This demo demonstrates that adding the following polyfill in polyfills.ts works: import '@webcomponents/webcomponentsjs/custo ...

Acquire key for object generated post push operation (using Angular with Firebase)

I'm running into some difficulties grasping the ins and outs of utilizing Firebase. I crafted a function to upload some data into my firebase database. My main concern is obtaining the Key that is generated after I successfully push the data into the ...

Using jQuery's .html function to insert images

I have a unique counter that counts in currencies, such as Yen and Euro. Each number, as well as the currency sign and separator, are all displayed on the webpage using custom-designed icons. I utilize the display: flex; property in my container div and ap ...

Connect to a node.js server from a different network

Looking to set up a basic live chat using node.js, socket.io, and express. Managed to get it working on my local network, but wondering if there's a way for someone from another internet connection to connect without me needing to pay for server space ...