Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div style="margin-top: 30px;">
- <select id="data_value">
- <option>Select data type</option>
- <option>1</option>
- <option>2</option>
- </select>
- <button id="FilterButt" onclick="filter()">Filter</button>
- <table class="table table-bordered">
- <thead>
- <tr>
- <th>Current Date Time</th>
- <th>Time Difference</th>
- <th> GPS Date Time</th>
- <th>Data Type</th>
- <th>Address</th>
- <th>Distance</th>
- </tr>
- </thead>
- <tbody id="tbody">
- @foreach (var data in Model)
- {
- <tr>
- <td>@data.CurrentDateTime</td>
- <td></td>
- <td>@data.GPSDateTime</td>
- <td>@data.Datatype</td>
- <td>@data.Address</td>
- <td>@data.Distance</td>
- </tr>
- }
- </tbody>
- </table>
- <br/>
- function filter() {
- $("#tbody").empty();
- var data = $("#data_value").val();
- var model = {
- data: data
- };
- $.ajax({
- url: '@Url.Action("Filtering", "Home")',
- contentType: 'application/json; charset=utf-8',
- data: JSON.stringify(model),
- type: 'POST',
- dataType: 'json',
- processData: false,
- success: function(data) {
- var list = data;
- for (var i = 0; i <= list.length - 1; i++) {
- var valuesList =
- '<td> ' +
- list[i].imei +
- '</td>' +
- '<td > ' +
- list[i].currentTime +
- '</td>' +
- '<td class="title"> ' +
- list[i].gpsDate +
- '</td>' +
- '<td>' +list[i].dataType+
- '</td>' +
- '<td>' +list[i].adress+
- '</td>' +
- '<td>' +list[i].distance+
- '</td>';
- $("#tbody").append('<tr>' + valuesList + '</tr>');
- };
- timeDifference();
- }
- });
- function timeDifference() {
- var rows = $('#tbody tr');
- for (i = 1; i < rows.length; i++) {
- // Get the rows
- var previousRow = rows.eq(i - 1);
- var currentRow = rows.eq(i);
- // Get the dates from the first column
- var previousDate = new Date(previousRow.find('td').eq(0).text()).getTime();
- var currentDate = new Date(currentRow.find('td').eq(0).text()).getTime();
- // Calculate time
- var time = currentDate - previousDate; // gets the difference in milliseconds
- var hours = Math.floor(time / 3600 / 1000);
- var minutes = Math.floor((time / 60 / 1000) - (hours * 60));
- var seconds = (time / 1000) - (hours * 3600) - (minutes * 60);
- // Format value (modify as required)
- var timeDiff = hours + ':' + minutes + ':' + seconds;
- // Update column
- currentRow.find('td').eq(1).text(timeDiff);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement