1

How can I represent the following json object in bootstrap-table

{
  "SourceFile": "/opt/lampp/htdocs/metaviewer/uploads/2438071792_19ed1df293_o.jpg",
  "ExifToolVersion": 10.8,
  "FileName": "2438071792_19ed1df293_o.jpg",
  "Directory": "/opt/lampp/htdocs/metaviewer/uploads",
  "FileSize": "123 kB",
  "FileModifyDate": "2019:07:01 21:59:19-05:00",
  "FileAccessDate": "2019:07:01 21:59:19-05:00",
  "FileInodeChangeDate": "2019:07:01 21:59:19-05:00",
  "FilePermissions": "rw-r--r--",
  "FileType": "JPEG",
  "FileTypeExtension": "jpg",
}

I want to represent a column with the (key) and the next column with the (value) of the json object but that is recursive, that does not have to be specified in the value field, that works for N key records: value

1 Answer 1

2

I have solved the problem based on https://jsfiddle.net/wenyi/e3nk137y/2556/

var objectJson = {
  "SourceFile": "/opt/lampp/htdocs/metaviewer/uploads/2438071792_19ed1df293_o.jpg",
  "ExifToolVersion": 10.8,
  "FileName": "2438071792_19ed1df293_o.jpg",
  "Directory": "/opt/lampp/htdocs/metaviewer/uploads",
  "FileSize": "123 kB",
  "FileModifyDate": "2019:07:01 21:59:19-05:00",
  "FileAccessDate": "2019:07:01 21:59:19-05:00",
  "FileInodeChangeDate": "2019:07:01 21:59:19-05:00",
  "FilePermissions": "rw-r--r--",
  "FileType": "JPEG",
  "FileTypeExtension": "jpg"
}

function responseHanlder(res) {
  var data = [];
  for (var key in res) {
      data.push({
          key: key,
          value: res[key]
      });
  }
  return data;
}

$(function () {
  $('#table').bootstrapTable({
    columns: [{
      field: 'key',
      title: 'key name'
    }, {
      field: 'value',
      title: 'value name'
    }],
      data: responseHanlder(objectJson)
  });
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/[email protected]/dist/bootstrap-table.min.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>

<table id="table"> </table>

enter code here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.