Sort input elements using dom-text and absolute sort

Sort input elements using dom-text and absolute sort

Peter_ChurchPeter_Church Posts: 2Questions: 1Answers: 0

Hello,

I have a column of dates inside input elements.

I can sort these using the dom-text function and it works ok. I now need to find some way to leave all the 'null' input boxes at the bottom (i.e absolute sort) but I cannot see anywhere how to do this in conjunction with the dome-text function.

Does someone know if this can be done?

Greatly appreciate any help on this

Answers

  • Peter_ChurchPeter_Church Posts: 2Questions: 1Answers: 0
    edited August 2022

    After several hours of research, I finally managed to get the two functions working together. Quite simple in the end!

                                    $.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();
                                                } );
                                            };
                                    
    
                                    $(document).ready(function () {
    
                                        var myCol1 = $.fn.dataTable.absoluteOrder( {
                                            value: '', position: 'bottom'
                                 } );
    
    
                                        $('#example').DataTable({
                                            paging: false,
                                            ordering: true,
                                            searching:false, 
                                            info: false,
                                            columnDefs: [
                                                {
                                                     orderDataType: 'dom-text',
                                                    targets: 2
                                                },
                                                {
                                                    type: myCol1,
                                                    targets: 2
                                                }
                                            ],
                                        });
                                    });
    
Sign In or Register to comment.