1

I have a sorting issue in my project. After sorting I got a result like this in the image Here is the issue

  <td className="dashboard_table-cell" title={'Created Date: ' + Queue.CreatedDate}>{Queue.CreatedDate}</td>

what format will I apply to my code to display the correct sorting order?

9
  • 2
    maybe you can try format into ISO string "YYYY-MM-DDTHH:MM:SS.MMMZ" Commented Oct 4, 2019 at 6:56
  • what library do you use to make the table? Commented Oct 4, 2019 at 7:33
  • it's just a HTML table Commented Oct 4, 2019 at 8:09
  • @JeeMok can you show me an example? Commented Oct 4, 2019 at 8:26
  • @MilyAlfrad can you give me one example of Queue.CreatedDate Commented Oct 4, 2019 at 8:59

2 Answers 2

2

I found it in my own way,

 sort(event){
            if(event.target.id === 'CreatedDate'){
            gridData = _.orderBy(gridData, (o) => moment(o[event.target.id])._d, 
      order[event.target.id] ? 'asc' : 'desc');
            }
   else
        gridData = _.orderBy(gridData, (o) => typeof o[event.target.id] === 'string' ? o[event.target.id].trim().toLowerCase() : o[event.target.id], order[event.target.id] ? 'asc' : 'desc');
    }

     <th id="CreatedDate" className="dashboard_table-head" onClick={this.sort}>Created Date {order.CreatedDate ? <i id="CreatedDate" className="fa fa-sort-asc" /> : <i id="CreatedDate" className="fa fa-sort-desc" />}</th>
    ..............................................................
     <td className="dashboard_table-cell" title={'Created Date: ' + Queue.CreatedDate}>{moment(Queue.CreatedDate).format('MM-DD-YYYY HH:mm:ss')}</td>
Sign up to request clarification or add additional context in comments.

Comments

0

you should try sort by time like

createdDate.getTime()

so for every date, you will have you will compare createdDate.getTime() of each item.

for every Date() the value we get from .getTime() will be unique and be incrementing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.