Date values via json using moments.js are not recognized in SearchBuilder

Date values via json using moments.js are not recognized in SearchBuilder

badijdbadijd Posts: 1Questions: 0Answers: 0
edited May 4 in SearchBuilder

I am not sure if I am setting the date (or number) values correctly (see below). The number columns such as QTY Received and pricing are recognized in searchbuilder and by default offer condition values such as Greater/Less Than and Between. The date received column is recognized as text no matter the returned format (mm/dd/yyyy or dd mmm yyyy or yyyy ... etc). I would like to be able to have the default options such as Greater/Less Than and Between for date columns. The json return format is yyyy-mm-dd hh:mm:ss.
What am missing. Your assistance is greatly appreciated!

$(document).ready(function() {
                $('.example').DataTable( {
                    "dom": '<Bfip<t>lp>',               
                    "language": {
                        "search": "_INPUT_",
                        "searchPlaceholder": "Search...",
                        "zeroRecords": "No entries match your search",
                        "emptyTable": "No entries to display",
                        "loadingRecords": "Please wait - loading...<br> <img src='/Common/CoreElements.nsf/images/pouring-coffee.gif' height='300' width='300'>"
                    },
                    "ajax": {
                        "url":'../avNIIN',
                        "type": 'GET',  
                        "dataType": 'json',
                        "dataSrc":'',
                        "defaultRender": 'true'
                    },
                  
                    "columns": [
                        { data: 'Title' },
                        { data: 'DateReceived', 
                            'render': function(data, type) {
                                if(data == ''){
                                    return type === 'sort' ? data: ''
                                } else { 
                                    return type === 'sort' ? data : moment(data).format('DD MMM YYYY') 
                                }
                            }
                        },
                        { data: 'QuantityReceived',
                            'className': 'dt-body-right'
                        },
                        { data: 'UnitPrice', 
                            'render': $.fn.dataTable.render.number( ',', '.', 0, '$' ),
                            'className': 'dt-body-right'
                            },
                        { data: 'TotalPrice', 
                            'render': $.fn.dataTable.render.number( ',', '.', 0, '$' ),
                            'className': 'dt-body-right'
                        }
                    ],
                  
                    "lengthMenu": [[25, 50, 100, 250, -1], [25, 50, 100, 250, "All"]],
                    "fixedHeader": true,
                        "select": true,
                  
                    "buttons": [
                        'searchBuilder',
                        {
                        extend: 'collection',
                        text: 'Export Data',
                        buttons: [
                            {
                                extend: 'excelHtml5',
                                title: ' Export'
                            },
                            {
                                extend: 'pdfHtml5',
                                title: ' Export'
                            },
                            {
                                            extend: 'print',
                                            title: ' Export'
                            }
                        ]
                        }
                    ],
                });
            });

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Replies

  • colincolin Posts: 12,479Questions: 0Answers: 2,117

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.