Datatables 1.10+ & ASP.NET MVC 5 with Server Side Integration

Datatables 1.10+ & ASP.NET MVC 5 with Server Side Integration

kmd1970kmd1970 Posts: 36Questions: 8Answers: 1
edited June 2017 in DataTables 1.10

I recently had to convert a ColdFusion application to ASP.NET MVC 5 application.

As I am fairly new to ASP.NET, this post was a time saver:

https://echosteg.com/jquery-datatables-asp.net-mvc5-server-side

This project uses samples of the original code created by Marien Monnier (French to English):

https://translate.google.com/translate?sl=fr&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=https%3A%2F%2Fblog.goood.pro%2F2014%2F11%2F21%2Fmvc-utilisation-de-jquery-datatables-en-mode-serveur%2F&edit-text=

Replies

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    Thanks for posting this. I'm sure others will find it useful.

    Regards,
    Allan

  • kmd1970kmd1970 Posts: 36Questions: 8Answers: 1

    @allan

    I am trying to add the ability to use different data for each column type in the datatables mvc 5 code.

    As outlined in columns.data. Use different data for the different data types requested by DataTables ( _, filter, display, type or sort).

    I actually have 7 columns in my table but I shortened to 2 columns for this example

    columns: [
    { data: 'id'},
    { data: { '_':'name', 
                 'display': 'name_display', 
                 'filter': 'name_filter', 
                 'sort': 'name_sort' } }
    ]
    

    Step 1 in DatatablesViewModel.cs change the Data property to type object:

    /// Column's data source, as defined by columns.data.
    public string Data { get; set; }
    

    to

    /// Column's data source, as defined by columns.data.
    public object Data { get; set; }
    

    Below you can see that columns[0].Data (id) is correctly set to a string value of id

    alt text

    However, columns[2].Data (name) has a value of {object}`.

    alt text

    I was expecting to see

    alt text

    Questions:
    1. How do I get the _ , display, filter and sort values from the {object}?
    2. Am I using the wrong type for Data (get; set; }?
    3. How do I get the column.data parameter to hold a string or object value in C#?

    Sorry I am new to C#.

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    I have created the classes that the data object set from DataTables via ajax. Hope this will save you some time and hopefully it is a good starting point for you.

    https://github.com/bindrid/DataTablesServerSide

  • vladko_szvladko_sz Posts: 2Questions: 0Answers: 0

    Hi, you may check this library which works on IQueryable and can be used with Entity Framework:
    https://github.com/VladimirDimov/jQuery-Datatables-Server-Side-Processing

This discussion has been closed.