MultiTable MultiRow (childrows) in MVC

MultiTable MultiRow (childrows) in MVC

KennethWintherKennethWinther Posts: 5Questions: 2Answers: 0

Hello everybody :)
I've followed this example: https://datatables.net/examples/api/row_details.html.
I've used it in my MVC5 ASP .NET app and it worked fine :)

I'm using a controller and EF as model to get the data in two tables as such:

public ActionResult GetService()
{
using (MyDatabaseEntities dc = new MyDatabaseEntities())
{
dc.Configuration.LazyLoadingEnabled = false;
dc.Configuration.AutoDetectChangesEnabled = true;

            var servicelist = dc.ServiceInfoes.OrderBy(a => a.ServiceID).ToList();
            return Json(new { data = servicelist }, JsonRequestBehavior.AllowGet);
        }
    }~~~~

How do i get the data from my secound table into the child rows? :D
I can get data form my "table 1" into the child rows, but not the data from "table 2".
Does this have anything to do with the function (d) in the example?
Or do I need to modify my GetService Method to .include "table 2"? ~~~~

Thank you very much for your time all :)

Answers

  • kthorngrenkthorngren Posts: 20,393Questions: 26Answers: 4,786

    I'm not familiar with MVC but maybe we can start with some basic questions:

    1. Are both tables displayed on the same page?
    2. If you select a row in table 1 what data is the tie to table 2?

    One option is to include the table 2 data with the table 1 data and the format function can just access the table 2 data elements. This would require the server side script to be changed.

    Another option that I would consider is to use filter() to get the data from table 2 based on the criteria from table 1.

    Kevin

  • KennethWintherKennethWinther Posts: 5Questions: 2Answers: 0
    1. Yes - Table 1 is in a DataTable and Table 2 is a small table which is nested under table 1 (child rows).
    2. Normal 1serviceinfo has 1 or more ServiceTexts :)
      Do you know of any problems when using EF's .Include with Json and DataTable?
      Filter you say, will look into it.
      Thank you :)
This discussion has been closed.