2
0
Fork 0

choix d'ordre fonctionne pour tous les tris qui en demandent, changement des value dans les options à valider

Dieser Commit ist enthalten in:
Florian Ehr 2021-02-06 11:07:46 +01:00
Ursprung 1de84726e0
Commit cdf43438cc
2 geänderte Dateien mit 26 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -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>

Datei anzeigen

@ -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);
}); });
} }