使用tablesorter对英国日期进行排序

时间:2019-01-09 11:27:14

标签: jquery tablesorter datefilter

我正在使用TableSorter对表进行排序,因为我正试图替换数据表(因为它难以处理大型数据集)。我正在使用以下Javascript:

$('#tableID').tablesorter({
    widgets: ["saveSort"] ,
    dateFormat : "dd/mm/yyyy" // set the default date format
});

它不起作用。如果我对日期列之一进行排序,则其排序如下

  • 23/08/2019
  • 2019/04/30
  • 11/08/2019

这甚至没有数字排序,所以我很困惑。我也尝试过使用dateformat:'uk',但没有运气

有人有什么想法吗?

2 个答案:

答案 0 :(得分:2)

我实际上只是发现日期格式应该是“ ddmmyyyy”而不是“ dd / mm / yyyy”

我一定只是需要橡皮鸭,谢谢

答案 1 :(得分:1)

我的猜测是,您应该在JS中键入不带斜杠的格式,但在HTML文件中使用斜杠保留格式。就您而言:

public void dropFile(WebElement target, int offsetX, int offsetY) {
        String workingDir = System.getProperty("user.dir");
        String filepath = workingDir + "\\Testdata.txt";
    //    JavascriptExecutor jse = (JavascriptExecutor) driver;

        String JS_DROP_FILE = "var args = arguments,"+
                "element = args[0],"+
                "offsetX = args[1],"+
                "offsetY = args[2],"+
                "doc = element.ownerDocument || document;"+

              "for (var i = 0; ;) {"+
                "var box = element.getBoundingClientRect(),"+
                  "clientX = box.left + (offsetX || (box.width / 2)),"+
                  "clientY = box.top + (offsetY || (box.height / 2)),"+
                  "target = doc.elementFromPoint(clientX, clientY);"+

                "if (target && element.contains(target))"+
                    "break;"+

                "if (++i > 1) {"+
                  "var ex = new Error('Element not interactable');"+
                  "ex.code = 15;"+
                  "throw ex;"+
                "}"+

                "element.scrollIntoView({behavior: 'instant', block: 'center', inline: 'center'});"+
              "}"+

              "var input = doc.createElement('INPUT');"+
              "input.setAttribute('type', 'file');"+
              "input.setAttribute('multiple', '');"+
              "input.setAttribute('draggable','true');"+
              "input.setAttribute('style', 'position:fixed;z-index:2147483647;left:0;top:0;');"+
               "input.onchange = function (ev) {"+
                "input.parentElement.removeChild(input);"+
                "ev.stopPropagation();"+

                "var dataTransfer = {"+
                  "constructor   : DataTransfer,"+
                  "effectAllowed : 'all',"+
                  "dropEffect    : 'none',"+
                  "types         : [ 'Files' ],"+
                  "files         : input.files,"+
                  "setData       : function setData(){},"+
                  "getData       : function getData(){},"+
                  "clearData     : function clearData(){},"+
                 " setDragImage  : function setDragImage(){}"+
                "};"+
                 "input.ondrop = function dropHandler(ev) {"+
                 "console.log('File(s) dropped');"+
                 // Prevent default behavior (Prevent file from being opened)
                 "ev.preventDefault();"+
                 "if (ev.dataTransfer.items) {"+
    // Use DataTransferItemList interface to access the file(s)
                "for (var i = 0; i < ev.dataTransfer.items.length; i++) {"+
      // If dropped items aren't files, reject them
              "if (ev.dataTransfer.items[i].kind === 'file') {"+
              "var file = ev.dataTransfer.items[i].getAsFile();"+
              "console.log('... file[' + i + '].name = ' + file.name);"+
      "}"+
    "}"+
  "} else {"+
    // Use DataTransfer interface to access the file(s)
    "for (var i = 0; i < ev.dataTransfer.files.length; i++) {"+
      "console.log('... file[' + i + '].name = ' + ev.dataTransfer.files[i].name);"+
    "}"+
  "}"+ 
  // Pass event to removeDragData for cleanup
 "removeDragData(ev)"+
    "};"+
    "function removeDragData(ev) {"+
     "console.log('Removing drag data');"+
     "if (ev.dataTransfer.items) {"+
       // Use DataTransferItemList interface to remove the drag data
       "ev.dataTransfer.items.clear();"+
     "} else {"+
       // Use DataTransfer interface to remove the drag data
       "ev.dataTransfer.clearData();"+
     "}"+
   "}"+

                "if (window.DataTransferItemList) {"+
                  "dataTransfer.items = Object.setPrototypeOf(Array.prototype.map.call(input.files, function(file) {"+
                    "return {"+
                      "constructor : DataTransferItem,"+
                      "kind        : 'file',"+
                      "type        : file.type,"+
                      "getAsFile   : function getAsFile () { return file },"+
                      "getAsString : function getAsString (callback) {"+
                        "var reader = new FileReader();"+
                        "reader.onload = function(ev) { callback(ev.target.result) };"+
                        "reader.readAsText(file);"+
                     " }"+
                    "}"+
                  "}), {"+
                    "constructor : DataTransferItemList,"+
                    "add    : function add(){},"+
                    "clear  : function clear(){},"+
                    "remove : function remove(){}"+
                 " });"+
                "}"+
                "['dragenter','dragover', 'drop', 'dragleave'].forEach(function (type) {"+
                  "var event = doc.createEvent('CustomEvent');"+
                  "event.initCustomEvent(type, true, true, doc.defaultView, 0, 0, 0, clientX, clientY, false, false, false, false, 0, null);"+
                  "Object.setPrototypeOf(event, null);"+
                  "event.dataTransfer = dataTransfer;"+
                  "Object.setPrototypeOf(event, DragEvent.prototype);"+
                  "target.dispatchEvent(event);"+
               " });"+
              "};"+
              "doc.documentElement.appendChild(input);"+
            "input.getBoundingClientRect();"+ /* force reflow for Firefox */
              "return input;";
        WebElement input = (WebElement)driverUtil.ngDriver.evaluateScript(target, JS_DROP_FILE);
       // WebElement input = (WebElement)((JavascriptExecutor) driver).executeScript(JS_DROP_FILE, target, offsetX, offsetY);
        input.sendKeys(filepath);
    }

在官方文档中阅读有关此特定问题的更多信息,它也有一个很好的例子: https://mottie.github.io/tablesorter/docs/example-option-date-format.html