jeudi 27 juillet 2017

JQuery Custom Column Sorting not working for columns that are alphanumeric

I have set up custom JQuery column sorts that work for numeric or alphabetical data types but i can't get it to work for alphanumeric. I would imagine the numbers get sorted to the top and the alphas go underneath but i cannot get it to do anything. Im using Bootstrap Data Tables and JQuery. My custom statements are below but i can't see how to allow them for alphanumeric mixed field types. Has anyone have a solution or point me in the direction of where i would find one? thanks in advance.

    /* Create an array with the values of all the input boxes in a column */
$.fn.dataTable.ext.order['dom-text'] = function(settings, col) {
    return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
        return $('input', td).val();
    });
}

/* Create an array with the values of all the input boxes in a column, parsed as numbers */
$.fn.dataTable.ext.order['dom-text-numeric'] = function(settings, col) {
    return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
        return $('input', td).val() * 1;
    });
}

/* Create an array with the values of all the select options in a column */
$.fn.dataTable.ext.order['dom-select'] = function(settings, col) {
    return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
        return $('select', td).val();
    });
}

/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTable.ext.order['dom-checkbox'] = function(settings, col) {
    return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
        return $('input', td).prop('checked') ? '1' : '0';
    });
}

/* Initialise the table with the required column ordering data types */
$(document).ready(function() {
    $('#tab_logic').DataTable({
        "columns": [
            { "orderDataType": "dom-text-numeric" },
            { "orderDataType": "dom-text" },
            { "orderDataType": "dom-select" },
            { "orderDataType": "dom-select" },
            { "orderDataType": "dom-checkbox" }
        ]
    });




Aucun commentaire:

Enregistrer un commentaire