alfajango / jquery-dynatable

A more-fun, semantic, alternative to datatables
http://www.dynatable.com
Other
2.78k stars 363 forks source link

creat link from url in json array #314

Open Wicko-Design opened 4 years ago

Wicko-Design commented 4 years ago

In our json array we have urls that link to specific pages. How can I add this links to a button in the table?

<table id="job-table" class="table table-bordered">
                        <thead>
                            <tr>
                                <th>title</th>
                                <th>absolute_url</th>
                                <th>jobLink</th>
                                <th>locationName</th>
                                <th>updated_at</th>
                                <th>id</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <script>
                        var $dataTable = $('#job-table');
                        $.getJSON('https://boards-api.greenhouse.io/v1/boards/oni/jobs', ({jobs}) => {
                            if (!jobs) return;
                            const flattenJobs = jobs.map(({title, absolute_url, location, updated_at, id}) => ({
                                title,
                                absolute_url,
                                updated_at,
                                locationName: location.name, 
                                id
                            }));

                            console.log(flattenJobs);
                            $dataTable.dynatable({
                                dataset:{
                                    records: flattenJobs
                                },
                                features: {
                                    paginate: true,
                                    recordCount: true,
                                    sorting: true,
                                    search: true,
                                }
                            });
                        });
                    </script>

Sample json

jobs: 
  0:  
absolute_url: "https://oni.bio/careers?gh_jid=4195285002"
internal_job_id: 4172877002
location:  
name: "Oxford"
metadata: []
id: 4195285002
updated_at: "2019-08-27T10:00:41-04:00"
requisition_id: null
title: "Account Manager"
1:  
absolute_url: "https://oni.bio/careers?gh_jid=4365372002"
internal_job_id: 4305685002
location: 
name: "Oxford"
metadata: []
id: 4365372002
updated_at: "2019-09-03T11:41:03-04:00"
requisition_id: null
title: "Backend Software Engineer (DevOps)"
2:  
absolute_url: "https://oni.bio/careers?gh_jid=4187013002"
internal_job_id: 4165585002
location:  
name: "Oxford"
metadata: []
id: 4187013002
updated_at: "2019-08-27T10:00:41-04:00"
requisition_id: null
title: "C++ Software Engineer"