choix d'ordre fonctionne pour tous les tris qui en demandent, changement des value dans les options à valider
This commit is contained in:
parent
1de84726e0
commit
cdf43438cc
2 changed files with 26 additions and 18 deletions
|
@ -20,10 +20,10 @@ class Sort extends Component {
|
||||||
<div id="selectBlock">
|
<div id="selectBlock">
|
||||||
<div id="selectBox">
|
<div id="selectBox">
|
||||||
<select id="sortSelect" onChange={this.props.handleChangeSortType}>
|
<select id="sortSelect" onChange={this.props.handleChangeSortType}>
|
||||||
<option className="optionSort" value="Ordre Alphabétique">Ordre Alphabétique</option>
|
<option className="optionSort" value="name">Ordre Alphabétique</option>
|
||||||
<option className="optionSort" value="Catégorie">Catégorie</option>
|
<option className="optionSort" value="category_id">Catégorie</option>
|
||||||
<option className="optionSort" value="Quantité">Quantité</option>
|
<option className="optionSort" value="quantity">Quantité</option>
|
||||||
<option className="optionSort" value="Prix">Prix</option>
|
<option className="optionSort" value="price">Prix</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -68,7 +68,7 @@ export default class Stock extends React.Component {
|
||||||
let sorted;
|
let sorted;
|
||||||
//TRI PAR ORDRE ALPHABETIQUE OU PRIX
|
//TRI PAR ORDRE ALPHABETIQUE OU PRIX
|
||||||
if (sortType === "name"){
|
if (sortType === "name"){
|
||||||
this.setState({orderIsHidden: false})
|
this.setState({orderIsHidden: false}) //choix d'ordre possible
|
||||||
if (this.state.lowToHigh) {
|
if (this.state.lowToHigh) {
|
||||||
//ordre alphabétique croissant
|
//ordre alphabétique croissant
|
||||||
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
@ -78,7 +78,7 @@ export default class Stock extends React.Component {
|
||||||
}
|
}
|
||||||
} else if (sortType === "price") {
|
} else if (sortType === "price") {
|
||||||
console.log('tri pix')
|
console.log('tri pix')
|
||||||
this.setState({orderIsHidden: false})
|
this.setState({orderIsHidden: false}) //choix d'ordre possible
|
||||||
if (this.state.lowToHigh) {
|
if (this.state.lowToHigh) {
|
||||||
//ordre croissant
|
//ordre croissant
|
||||||
sorted = [...this.state.articles].sort((a, b) => a.price - b.price)
|
sorted = [...this.state.articles].sort((a, b) => a.price - b.price)
|
||||||
|
@ -167,26 +167,34 @@ export default class Stock extends React.Component {
|
||||||
this.setState({onEditCategory:false})
|
this.setState({onEditCategory:false})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleChangeSortType = (e) => {
|
||||||
|
// console.log(e.target.value)
|
||||||
|
// this.setState({sortType:e.target.value},()=>{
|
||||||
|
// if (this.state.sortType === "Ordre Alphabétique"){
|
||||||
|
// this.sortArticles("name")
|
||||||
|
// } else if(this.state.sortType === "Catégorie"){
|
||||||
|
// this.sortArticles("category_id")
|
||||||
|
// } else if(this.state.sortType === "Quantité"){
|
||||||
|
// this.sortArticles("quantity")
|
||||||
|
// } else if(this.state.sortType === "Prix"){
|
||||||
|
// this.sortArticles("price");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
handleChangeSortType = (e) => {
|
handleChangeSortType = (e) => {
|
||||||
console.log(e.target.value)
|
console.log(e.target.value)
|
||||||
this.setState({sortType:e.target.value},()=>{
|
this.setState({sortType: e.target.value}, () => {
|
||||||
if (this.state.sortType === "Ordre Alphabétique"){
|
this.sortArticles(this.state.sortType)
|
||||||
this.sortArticles("name")
|
|
||||||
} else if(this.state.sortType === "Catégorie"){
|
|
||||||
this.sortArticles("category_id")
|
|
||||||
} else if(this.state.sortType === "Quantité"){
|
|
||||||
this.sortArticles("quantity")
|
|
||||||
} else if(this.state.sortType === "Prix"){
|
|
||||||
this.sortArticles("price");
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//Gère le choix de tri par ordre croissant ou décroissant quand c'est possible avec le tri actuel
|
//Gère le choix de tri par ordre croissant ou décroissant quand c'est possible avec le tri actuel
|
||||||
handleChangeSortOrder = e => {
|
handleChangeSortOrder = e => {
|
||||||
this.setState({lowToHigh: (this.state.lowToHigh + 1) % 2},() => {
|
this.setState({lowToHigh: (this.state.lowToHigh + 1) % 2},() => {
|
||||||
this.sortArticles("name");
|
console.log(this.state.sortType)
|
||||||
|
this.sortArticles(this.state.sortType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue