Skip to content

Commit

Permalink
Fix datatable script to match new date format
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Sep 14, 2018
1 parent ebe44d2 commit 0298696
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
22 changes: 2 additions & 20 deletions app/assets/javascripts/edi_error_reports.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
jQuery(document).ready(function($) {
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-uk-pre": function ( a ) {
var ukDatea = a.split('/');
var yearWithoutTime = ukDatea[2].split(' ')[0];
return (yearWithoutTime + ukDatea[1] + ukDatea[0]) * 1;
},
"date-uk-asc": function ( a, b ) {
console.log("asc");
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"date-uk-desc": function ( a, b ) {
console.log("desc");
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );

$(document).ready(function() {
$('table').DataTable({
columnDefs: [
{ type: 'date-uk', targets: 0 } // define 'run' column as date
]
"order": [[ 0, "desc" ]]
});

$('input#edi_errors_day').on('change', function() {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/edi_error_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EdiErrorReportsController < ApplicationController
has_scope :type

def index
@edi_error_report = apply_scopes(EdiErrorReport.order(:run)).all
@edi_error_report = apply_scopes(EdiErrorReport.order(run: :desc)).all
rescue StandardError => e
flash[:error] = e.message
redirect_to edi_error_reports_path
Expand Down

0 comments on commit 0298696

Please sign in to comment.