Display and Sorting different values

Display and Sorting different values

visionxvisionx Posts: 22Questions: 4Answers: 5

Hi all,

I have a situation where want to display DATE in one table field and when sorting happens it should be relevant to DATE & TIME. I am returning TIMESTAMP from the database. Basically I want to display DATE in the table field and when user perform searing it should be according to the TIMESTAMP.

How could I achieving this?

This question has an accepted answers - jump to answer

Answers

  • john_ljohn_l Posts: 45Questions: 0Answers: 12
    Answer ✓

    This is pretty simple - there's a few ways you can achieve it - for example:
    1) Wrap the date in a span, and add a 'ref' attribute to the span that contains the timestamp, and then use a custom sort function for the column that sorts based on the timestamp in the ref attribute.
    2) Put the timestamp in a non-visible column, and configure your date column to use the timestamp column as the sort value data source

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Also you could have your database return the timestamp and the date portion of it separately. I'm sure MySQL has a function to achieve this, although I don't remember what it is.
    Then use a hidden column as John says.

  • visionxvisionx Posts: 22Questions: 4Answers: 5

    Thanks john_l and tangerine for the support.

    I managed to get it worked as follows.

    Sample Time Stamp from DB : 11/13/13 10:45AM

    Configuration in Data table :

                    "aoColumns" : [ 
    
                                    {"mData" : "orderedDate","mRender": function ( data, type, full ) {
                                        var date = data;
                                        if(type == "display"){
                                            var dateTime = data.split(" ");
                                            date = dateTime[0];
                                        }
                                        return date;
                                    }}]
    
This discussion has been closed.