2

I am new to Angular 4 and i am trying to implement the ngx-datatble by following the approach defined in ngx-datatable github and i am able to populate the table, however my confusion starts when i am trying to populate the data from a JSON object. The row and column array are bonded with the "name" property and same is being shown as header. But in actual JSON we will have camel-case naming convention.How to populate that data with proper header.

Please advice, any help would be appreciated..!!!

Thanks in Advance

Please find my code below:

HTML

<div>
 <ngx-datatable
 [rows]="rows"
 [columns]="columns">
 </ngx-datatable>
</div>

TS File

rows = [
 { Firstname: 'Austin', gender: 'Male', company: 'Swimlane' },
 { name: 'Dany', gender: 'Male', company: 'KFC' },
 { name: 'Molly', gender: 'Female', company: 'Burger King' },
];
columns = [
 { prop: 'Firstname' },
 { name: 'Gender' },
 { name: 'Company' }
];

Target JSON

[{
 "firstName":"abc",
 "lastName":"xyz",
 "address_1":"lorem ipsum",
 "address_2":"and so on"
},{
 "firstName":"abc",
 "lastName":"xyz",
 "address_1":"lorem ipsum",
 "address_2":"and so on"
},{
 "firstName":"abc",
 "lastName":"xyz",
 "address_1":"lorem ipsum",
 "address_2":"and so on"
}]
asked Feb 19, 2018 at 6:33
1

1 Answer 1

2
columns = [
 { 
 prop: 'Firstname', // prop will bind to the json property
 name : 'First Name' // You can define the name here 
 // ( Column label. If none specified, it will use the prop value and decamelize it. )
 },
 { name: 'Gender' },
 { name: 'Company' }
];

For More Detail : Read

answered Feb 19, 2018 at 7:26
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.