hrkymkw / Blip

MVC Project
0 stars 0 forks source link

Datatables #20

Open ssiko opened 9 years ago

ssiko commented 9 years ago

Hiro,

You no longer have to draw the TRs/TDs in the view, datatables handles all of this, if you pass it good JSON and have a valid table in the html sitting out there that matches the JSON it will work.

I believe that will address the "rendering" issue you explained to me before.

ssiko commented 9 years ago

Here is the object I used to create JSON for datatables, if you are curious about how it works let me know. There is generics involved.

public class GridReturnType<T>
{
    public int sEcho = 2;

    public int iTotalRecords { get; set; }

    public int iTotalDisplayRecords { get; set; }

    public List<T> aaData { get; set; }
}
ssiko commented 9 years ago

And also objects for server side paging, sorting, searching, etc (just in case) :

public HttpResponseMessage Get([FromUri] DatatablesSettings ts) {

...

public class DatatablesSettings
{
    public int sEcho { get; set; }
    public int iColumns { get; set; }
    public int iDisplayStart { get; set; }
    public int iDisplayLength { get; set; }
    public string sSearch { get; set; }
    public int iSortCol_0 { get; set; }
    public string sSortDir_0 { get; set; }
    public int iSortingCols {get; set; }
    public string mDataProp_0 { get; set; }
    public string sSearch_0 { get; set; }
    public bool bRegex_0 { get; set; }
    public bool bSearchable_0 { get; set; }
    public bool bSortable_0 { get; set; }
}
ssiko commented 9 years ago

sample HTML placeholder:

        <table id="doctorGrid">
            <thead>
                <tr>
                    <th>Tax ID</th>
                    <th>EIN/SSN</th>
                    <th>Organization</th>
                    <th>Doc ID</th>
                    <th>Name</th>
                    <th>Address</th>
                    <th>Taxonomy Code</th>
                    <th>Billing NPI</th>
                    <th>Rendering NPI</th>
                    <th>Legacy ID</th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>