Tuesday, September 26, 2017

Data Binding with Smart table from json file

i want to bind the json file to a smart table. How to use the loop function for the iteration.. please help
It only shows the design of smart table.
didn’t binding the data from json

this 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 used to retrieve 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 part

@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);
  });
}  
}

please anyone anyone know how to bind it ..help

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/09/26/data-binding-with-smart-table-from-json-file/
via @lzomedia #developer #freelance #web

No comments:

Post a Comment