0

I want to sort date from the product array ( date is one of the field in product). Please suggest me. Am using reactjs.

Please find the code that am using.

render() {

          let sortedDate = this.state.item.sort((a, b) => Date.parse(new Date(a.expected_ship_date("/").reverse().join("-"))) - Date.parse(new Date(b.expected_ship_date("/").reverse().join("-"))));
          let sortedDate1 = this.state.item.sort((a, b) => new Date(a.expected_ship_date) - new Date(b.expected_ship_date));

        return (
            <tr>
                <td><input name="line_number" type="text" value={ this.state.item.line_number } disabled={ this.props.mode }  className="form-control" onChange={ this.handleInputChange }/> </td>
                <td><input name="requested_ship_date" type="date" value={ this.state.item.expected_ship_date } disabled={ this.props.mode }  className="form-control" onChange={ this.handleInputChange }  /></td>

                <td>{sortedDate.map( (c, i) => <div>{c.expected_ship_date}</div>)}</td>
            </tr>

        );
}
3
  • 3
    Possible duplicate of Sort array by dates in React JS Commented Jul 28, 2017 at 12:30
  • That is not working for me. Uncaught TypeError: this.state.item.sort is not a function Commented Jul 28, 2017 at 12:41
  • probably this.state.item isnt an array. Commented Jul 28, 2017 at 13:24

0

Your Answer

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