This topic contains 3 replies, has 2 voices, and was last updated by Jai Jai 1 year, 1 month ago.

best Practices to Generation datatable meta with .Net Core 2.0


  • Phoenix DevCore
    Participant

    Posts: 19
    Member Reply #12242

    Hii 🙂 ,

    When i refresh or load datatable, i have see a (Headers Form Data) like this :

    datatable[pagination][total]:133
    datatable[pagination][page]:1
    datatable[pagination][pages]:27
    datatable[pagination][perpage]:5
    datatable[pagination][field]:
    datatable[pagination][sort]:
    datatable[pagination][query]:
    datatable[sort][sort]:
    datatable[sort][field]:
    datatable[query][status]:1
    datatable[query][type]:"active"

    My question is how to get this in C# .Net Core Application ? I used this code but when i want to read a datatable[query] i get NULL.

    The problem is that this field must be generic regardless of the fields it contains. For example, get this field as an array ['status', 'type']

     

    My code works with all others fields like page, perpage, … But i need a very better solution :

    dynamic meta = new
    {
    total = count,
    page = Convert.ToInt32(form["datatable[pagination][page]"].FirstOrDefault()),
    pages = Convert.ToInt32(form["datatable[pagination][pages]"].FirstOrDefault()),
    perpage = Convert.ToInt32(form["datatable[pagination][perpage]"].FirstOrDefault()),
    field = form["datatable[sort][field]"].FirstOrDefault(),
    sort = form["datatable[sort][sort]"].FirstOrDefault(),
    query = form["datatable[query]"].FirstOrDefault()
    };

    Thanks for help ^_^

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #12284

    Hi 🙂

    We only have example of backend in PHP code

    /docs/api_reference/datatables/demos/default.php

     

    Status and Type is the example for custom filter by column.

    This demo shows status and type dropdown filter.

    http://keenthemes.com/metronic/preview/?page=components/datatables/base/data-ajax&demo=default

     

    Thanks


    Phoenix DevCore
    Participant

    Posts: 19
    Member Reply #12307

    Hii Thanks for reply, 🙂

    I tried another solution for .NET Core users and it works perfectly, so I share you my code 🙂 :

    public static dynamic GetMeta(IFormCollection form)
    {
    dynamic meta = new ExpandoObject();
    var dict = form.ToDictionary(x => x.Key, x => x.Value.ToString());
    var res = new List<KeyValuePair<string, string>>();
    foreach (var d in dict)
    {
    res.Add(new KeyValuePair<string, string>(d.Key, d.Value));
    }
    return res;
    }

    I am very interested in your theme since version 1.0.1 it’s really great.

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #12320

    Hi 🙂

    Thanks for your code share.

    Good luck with your project.

    Thanks

You must be logged in to reply to this topic.