1

I am using this JSON file in one of my tables. As you can see, one of the JSON objects is logon which gives a plain text string for when the person logged on to the VATSIM Network.

My code for my table which is displayed on this site is as follows:

<table data-toggle="table" data-url="http://api.vateud.net/online/pilots/eg.json" data-cache="false" data-show-refresh="true" data-query-params="queryParams" data-pagination="true" data-search="true" data-page-list="5, 10, 25, 50, 100, All" data-height="400"
            data-sort-name="callsign" data-sort-order="asc">
                <thead>
                    <tr>
                        <th data-field="callsign" data-halign="center" data-align="center" data-sortable="true">Callsign</th>
                        <th data-field="name" data-halign="center" data-align="center" data-sortable="true">Name</th>
                        <th data-field="aircraft" data-halign="center" data-align="center" data-sortable="true">Aircraft</th>
                        <th data-field="origin" data-halign="center" data-align="center" data-sortable="true">Departure Airport</th>
                        <th data-field="destination" data-halign="center" data-align="center" data-sortable="true">Arrival Airport</th>
                        <th data-field="flight_type" data-halign="center" data-align="center" data-sortable="true">Type</th>
                        <th data-field="route" data-halign="center" data-align="center" data-sortable="true">Route</th>
                        <th data-field="altitude" data-halign="center" data-align="center" data-sortable="true">Altitude</th>
                        <th data-field="groundspeed" data-halign="center" data-align="center" data-sortable="true">Groundspeed</th>
                        <th data-field="transponder" data-halign="center" data-align="center" data-sortable="true">Squawk</th>
                        <th data-field="logon" data-halign="center" data-align="center" data-sortable="true">Logon Time</th>
                    </tr>
                </thead>
            </table> 

Is there a way of using Bootstrap-Tables to parse the plain text string into a formatted date and time stamp before injecting it into the table?

Thanks in advance.

1 Answers1

4

Try the data-Formatter option.

Example HTML:

<th data-field="name" data-formatter="nameFormatter">Name</th>

Example JS:

function nameFormatter(value) {
    return '<a href="https://github.com/wenzhixin/' + value + '">' + value + '</a>';
}

Reference URL:
http://jsfiddle.net/n7s43toq/

For your case below is the example / model format method.

function stringToDate (value) {
  var date = new Date(value*1000);
  // Hours part from the timestamp
  var hours = date.getHours();
  // Minutes part from the timestamp
  var minutes = "0" + date.getMinutes();
  // Seconds part from the timestamp
  var seconds = "0" + date.getSeconds();

  // Will display time in 10:30:23 format
  return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
}
Venkat.R
  • 7,420
  • 5
  • 42
  • 63
  • Thanks for the answer but can you adapt it to my individual scenario rather than a generic answer? – Theo Bearman Jan 07 '16 at 10:27
  • @TheoBearman - SO isnt here to write your application, but to help you solve problems - which this has done perfectly. Just replace inside your formatter with a call to stringToDate. If you dont know how to do that then you need to go find a javascript tutorial and learn basics as you risk causing all kinds of problems if you cant understand the code basics. – Daniel Brose Jan 12 '16 at 03:33