Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2017
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <div style="margin-top: 30px;">
  2. <select id="data_value">
  3. <option>Select data type</option>
  4. <option>1</option>
  5. <option>2</option>
  6. </select>
  7. <button id="FilterButt" onclick="filter()">Filter</button>
  8. <table class="table table-bordered">
  9. <thead>
  10. <tr>
  11. <th>Current Date Time</th>
  12. <th>Time Difference</th>
  13. <th> GPS Date Time</th>
  14. <th>Data Type</th>
  15. <th>Address</th>
  16. <th>Distance</th>
  17. </tr>
  18. </thead>
  19. <tbody id="tbody">
  20. @foreach (var data in Model)
  21. {
  22. <tr>
  23. <td>@data.CurrentDateTime</td>
  24. <td></td>
  25. <td>@data.GPSDateTime</td>
  26. <td>@data.Datatype</td>
  27. <td>@data.Address</td>
  28. <td>@data.Distance</td>
  29. </tr>
  30. }
  31. </tbody>
  32. </table>
  33. <br/>
  34.  
  35. function filter() {
  36. $("#tbody").empty();
  37. var data = $("#data_value").val();
  38. var model = {
  39. data: data
  40. };
  41. $.ajax({
  42. url: '@Url.Action("Filtering", "Home")',
  43. contentType: 'application/json; charset=utf-8',
  44. data: JSON.stringify(model),
  45. type: 'POST',
  46. dataType: 'json',
  47. processData: false,
  48. success: function(data) {
  49. var list = data;
  50. for (var i = 0; i <= list.length - 1; i++) {
  51. var valuesList =
  52. '<td> ' +
  53. list[i].imei +
  54. '</td>' +
  55. '<td > ' +
  56. list[i].currentTime +
  57. '</td>' +
  58. '<td class="title"> ' +
  59. list[i].gpsDate +
  60. '</td>' +
  61. '<td>' +list[i].dataType+
  62. '</td>' +
  63. '<td>' +list[i].adress+
  64. '</td>' +
  65. '<td>' +list[i].distance+
  66. '</td>';
  67.  
  68. $("#tbody").append('<tr>' + valuesList + '</tr>');
  69. };
  70. timeDifference();
  71. }
  72.  
  73. });
  74.  
  75. function timeDifference() {
  76. var rows = $('#tbody tr');
  77. for (i = 1; i < rows.length; i++) {
  78. // Get the rows
  79. var previousRow = rows.eq(i - 1);
  80. var currentRow = rows.eq(i);
  81. // Get the dates from the first column
  82. var previousDate = new Date(previousRow.find('td').eq(0).text()).getTime();
  83. var currentDate = new Date(currentRow.find('td').eq(0).text()).getTime();
  84. // Calculate time
  85. var time = currentDate - previousDate; // gets the difference in milliseconds
  86. var hours = Math.floor(time / 3600 / 1000);
  87. var minutes = Math.floor((time / 60 / 1000) - (hours * 60));
  88. var seconds = (time / 1000) - (hours * 3600) - (minutes * 60);
  89. // Format value (modify as required)
  90. var timeDiff = hours + ':' + minutes + ':' + seconds;
  91. // Update column
  92. currentRow.find('td').eq(1).text(timeDiff);
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement