Multiple sorting in Datatable with Serverside

Asked

Viewed 13 times

0

Greetings.

I have a table generated with the help of the Plugin Jquery Datatable with the ServerSide enabled and running a Script from the server side ASP.NET.

Only that I need this table to be dynamically ordered according to user clicks, according to this example of the documentation.

I was able to sort a single column at a time thanks to the following script:

List<ReportDetailPosicoes> detailPosicoes = (List<ReportDetailPosicoes>) Session["reportdetails"];
ReportPosicoes report = (ReportPosicoes) Session["report"];

// Carrega os dados relatório pela primeira vez e os adiciona na sessão.
if (detailPosicoes == null)
{
    //Adicionando ordenação Crescente por Data (padrão).
    detailPosicoes = detailPosicoes.OrderBy(detail => detail.Emissao).ToList();

    Session["report"] = report;
}
else
{ // Ordenação de acordo com o clique no cabeçalho da tabela
    string orderDir = form["order[0][dir]"];
    string orderStr = "Emissao";

    switch (form["order[0][column]"])
    {
        case "0":
            orderStr = "Placa";
            break;
        case "1":
            orderStr = "Emissao";
            break;
        case "2":
            orderStr = "Situacao";
            break;
    }

    if (orderDir == "desc")
        detailPosicoes = detailPosicoes.OrderByDescending(detail => detail.GetType().GetProperty(orderStr).GetValue(detail)).ToList();
    else
        detailPosicoes = detailPosicoes.OrderBy(detail => detail.GetType().GetProperty(orderStr).GetValue(detail)).ToList();
}

Session["reportdetails"] = detailPosicoes;

However, I have no idea how to sort by multiple columns.

Does anyone have a better notion? Is there a better way to do it than the one I executed? And to sort through more than one column at the same time, how can I?

Thanks in advance.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.