Bonjour à tous!

J'ai besoin de votre aide, je n'arrive pas à comprendre comment je peux effectuer des classements dans un tableau.

Avant, ce que je faisais, c'était que je modifiais la close "sort by" dans la requête linq, et ça me classait le tableau un peu comme j'en avais besoin.

Désormais, c'est un petit peu plus compliqué, certaines données de ce tableau ne sont pas obtenues via cette requête.

Comment pourrais-je faire pour que, lorsqu'un utilisateur clique sur le titre d'une colonne, tout le tableau se trie en fonction de cette colonne?



Voici le code utilisé dans la vue :

@Code
ViewData("Title") = "contactSearch"
Dim opportunite = ViewBag.opportunite
Dim message As String = ViewBag.message
Dim dist(,) As Double = ViewBag.distance
Dim cp As String = ViewBag.codePostal
Dim i = 0

End Code

<h2>Recherche sur les contacts</h2>


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 @Using Html.BeginForm(IsPost)
        @Html.TextBox("SearchString")
        @Html.DropDownList("opportunite", String.Empty)
        @Html.TextBox("dist")
        @<input type="submit" value="Create" />
        @<br />    
    End Using
 
 
    @If message.IsEmpty Then
   Else
        @Html.Raw("le code postal de l'opportunité est " + cp)
 
 
 
        @*Contacts*@
    @<fieldset>
        <legend>Contacts</legend>
        <div class="contact">
        <table border='1'>
                <tr>
                    <th>
                        Contact
                    </th>
                    <th>
                        Cote
                    </th>
                    <th>
                        telephone
                    </th>
                    <th>
                        mail
                    </th>
                    <th>
                        Localité
                    </th>
                    <th>
                        Distance
                    </th>
                    <th></th>
                </tr>
            @For Each contact In Model.Contacts
 
                         @<tr>
                        <td>
                            @Html.ActionLink(contact.nom + " " + contact.prenom, "Details", "Contacts", New With {.id = contact.idContact}, "Null")
                        </td>
                        <td>
                            @Html.Partial("~/Views/Shared/_EtoilesGde.vbhtml", contact.rating)
                        </td>
                        <td>
                            @Html.Raw(contact.telephone)
                        </td>
                        <td>
                            @Html.Raw(contact.mail)
                        </td>
                        <td>
                            @Html.Raw(contact.adresseLoc)
                        </td>
                        <td>
                            @Html.Raw(dist(3, i)) @Html.Raw(" km")
                        </td>
                        <td>
                            @Html.ActionLink("Edit", "Edit", "Contacts", New With {.id = contact.idContact}, "null") |
                            @Html.ActionLink("Delete", "Delete", "Contacts", New With {.id = contact.idContact}, "null")
                        </td>
                        <th>
 
                        </th>
                    </tr>
            i = i + 1
            Next contact
        </table>
        </div>
    </fieldset>        
End If
J'aimerais si possible ne rien avoir à changer dans le contrôleur. En attendant, je mets tout de même le code du contrôleur, au cas ou.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
Imports System.Data.Objects
Imports System.Linq.Expressions
Imports System.Linq
Imports System.Collections.Generic
Imports System
Imports LinqKit
Imports System.Math
 
Namespace MvcApplication4
    Public Class SearchController
        Inherits System.Web.Mvc.Controller
 
        Private db As schema_crmEntities1 = New schema_crmEntities1
 
        '
        ' GET: /Search
        <HttpGet()>
        Function contactSearch() As ActionResult
            ViewBag.opportunite = New SelectList(db.opportunite, "idOpportunite", "nomOffre")
            Dim table(3, 0) As Double
            table(3, 0) = 0
            ViewBag.distance = table
            Return View()
        End Function
 
 
 
        '
        'POST: /Search
        <HttpPost()>
        Function contactSearch(search As String, opportunite As opportunite, dist As Integer) As ViewResult
            Dim chaine As String = Request("searchString")
            Dim tabMot() = chaine.Split(New Char() {" "c})
            Dim distance As Integer = Request("dist")
            Dim message As String = "message"
            Dim opport As Integer = Val(Request("opportunite"))
            Dim n As Integer = 0
            Dim i As Integer = 0
 
 
            'Tout ce bloc sert à construire une liste de contacts répondant aux critères
            Dim predicate As Expression(Of Func(Of contact, Boolean))
            predicate = PredicateBuilder.False(Of contact)()
            For Each mot In tabMot
                Dim tmp = mot
                predicate = predicate.Or(Function(m) m.titre.Contains(tmp))
                predicate = predicate.Or(Function(m) m.departement.Contains(tmp))
                predicate = predicate.Or(Function(m) m.qualifications.Contains(tmp))
                predicate = predicate.Or(Function(m) m.langue1.Contains(tmp))
                predicate = predicate.Or(Function(m) m.langue2.Contains(tmp))
                predicate = predicate.Or(Function(m) m.langue3.Contains(tmp))
                predicate = predicate.Or(Function(m) m.langue4.Contains(tmp))
                predicate = predicate.Or(Function(m) m.langue5.Contains(tmp))
 
            Next
            Dim contacts = db.contact.AsExpandable().Where(predicate).ToList()
 
            'Compte la valeur de l'index du tableau de contacts
            For Each contact In contacts
                n += 1
            Next
            n -= 1
 
            'Cette requête sert à chercher le code postal d'une opportunité
            ViewBag.opportunite = New SelectList(db.opportunite, "idOpportunite", "nomOffre")
            Dim codePostal As Integer = (From a In db.opportunite, b In db.client
                                 Where a.idOpportunite = opport And a.FK_Client = b.idClient
                                 Select b.cpFact).First()
 
            'Requête qui sert à trouver les coordonnées du CP de l'opportunité
            Dim longOpp As Double = (From c In db.city
                                      Where c.code = codePostal
                                      Select c.longitude).First()
            longOpp = (longOpp * Math.PI) / 180 'conversion d'angles en radians
 
            Dim lattOpp As Double = (From d In db.city
                                      Where d.code = codePostal
                                      Select d.latitude).First()
            lattOpp = (lattOpp * Math.PI) / 180 'conversion d'angles en radians
 
            'Boucle qui va servir à récupérer les coordonnées des contacts sélectionnés
            Dim table(3, n) As Double
            For Each contact In contacts
                Dim tmp = contact
                table(0, i) = contact.idContact
                table(1, i) = (From d In db.city
                              Where d.code = tmp.adresseCP
                              Select d.longitude).First()
                table(1, i) = (table(1, i) * Math.PI) / 180
                table(2, i) = (From d In db.city
                              Where d.code = tmp.adresseCP
                              Select d.latitude).First()
                table(2, i) = (table(2, i) * Math.PI) / 180
                'table(3, i) = 2 * 6370 * Asin(Sqrt((Sin((table(2, i) - lattOpp) / 2) * Sin((table(2, i) - lattOpp) / 2) + Cos(table(1, i)) * Cos(lattOpp) * Sin((table(1, i) - longOpp) / 2) * Sin((table(1, i) - longOpp) / 2))))
                table(3, i) = Round(6370 * Acos(Sin(table(2, i)) * Sin(lattOpp) + Cos(table(2, i)) * Cos(lattOpp) * Cos(table(1, i) - longOpp)))
                i = i + 1
            Next
 
 
            ViewBag.distance = table
            ViewBag.message = message
            ViewBag.codePostal = Val(codePostal)
            Dim model = New SearchModel With {
                .Contacts = contacts
               }
 
            Return View(model)
        End Function
    End Class
End Namespace

Sinon, je suis un débutant, j'ai tout appris en grande partie grâce à ce forum. Si vous remarquez que je code mal, que je fais des choses inutiles, que mon code n'est pas propre ou autre, n'hésitez vraiment pas à me le faire remarquer. Je ne risque pas de mal le prendre.