3
Reply

[How] MVC multiple grid with different data

Bryan Gomez

Bryan Gomez

Nov 10 2017 2:57 AM
122
I need some help on how to achived the multiple grid in my mvc razor form with different data. Currently I only have 1 grid.
 
Here's my Model:
  1. namespace wmssoft_srm.Models  
  2. {  
  3.     public class ServiceList  
  4.     {  
  5.         public List<ServiceListData> GetData(DataTable oDT)  
  6.         {  
  7.             try  
  8.             {  
  9.                 List<ServiceListData> slData = new List<ServiceListData>();  
  10.                 for (int i = 0; i < oDT.Rows.Count; i++)  
  11.                 {  
  12.                     /*Parse date*/  
  13.                     string date = oDT.Rows[i]["ORDDATE"].ToString();  
  14.                     string result = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd");  
  15.   
  16.                     ServiceListData sl = new ServiceListData();  
  17.                     sl.date = Convert.ToDateTime(result);  
  18.                     sl.so_no = oDT.Rows[i]["ORDNUMBER"].ToString();  
  19.                     sl.serial = oDT.Rows[i]["SERIAL"].ToString();  
  20.                     sl.status = oDT.Rows[i]["STATUS"].ToString();  
  21.                     sl.technician = oDT.Rows[i]["TECH"].ToString();  
  22.   
  23.                     slData.Add(sl);  
  24.                 }  
  25.   
  26.                 return slData;  
  27.             }  
  28.             catch (Exception)  
  29.             {  
  30.                 throw new NotImplementedException();  
  31.             }  
  32.         }  
  33.     }  
  34.   
  35.     public class ServiceListData  
  36.     {  
  37.         public DateTime date { getset; }   
  38.         public string so_no { getset; }  
  39.         public string serial { getset; }  
  40.         public string status { getset; }  
  41.         public string technician { getset; }  
  42.     }  
  43.   
  44.     public enum Status  
  45.     {  
  46.         Open,  
  47.         Close  
  48.     }  

And in my controller:
My problem is that, how can I call the 2nd grid from my controller?
  1. public ActionResult Index()  
  2. {  
  3.    WCF_Service.InterfaceClient wmsSR = new WCF_Service.InterfaceClient();  
  4.     DataSet dsl = new DataSet();  
  5.     DataSet dsO = new DataSet();  
  6.     string a = "ValidateCredentials";  
  7.     string b = "~~ ~~ ~~";  
  8.   
  9.     b = wmsSR.fCallService("GetServiceList", b, ref dsl, ref dsO);  
  10.   
  11.     if (b == "OK ~~")  
  12.     {  
  13.         if (dsO.Tables[0].Rows.Count > 0)  
  14.         {  
  15.             DataTable oDT = new DataTable();  
  16.             oDT = dsO.Tables[0];  
  17.   
  18.             wmssoft_srm.Models.ServiceList slData = new Models.ServiceList();  
  19.             var myList = slData.GetData(oDT);  
  20.   
  21.             return View(myList);  
  22.         }  
  23.     }  
  24.   
  25.     return View();  

 Also this is  my View, the allJobs is my 2nd grid. The myJobs is my 1st grid which is working as expected based from my controller.
 
  1. @model List<wmssoft_srm.Models.ServiceListData>

    @using GridMvc.Html

  2. <div id="Tabs" role="tabpanel">  
  3.     <!-- Nav tabs -->  
  4.     <ul class="nav nav-tabs" role="tablist">  
  5.         <li class="active"><a href="#tabs-1" aria-controls="tabs-1" role="tab" data-toggle="tab">My Jobs</a></li>  
  6.         <li><a href="#tabs-2" aria-controls="tabs-2" role="tab" data-toggle="tab">All Jobs</a></li>  
  7.         <li><a href="#tabs-3" aria-controls="tabs-3" role="tab" data-toggle="tab">Unallocated Jobs</a></li>  
  8.     </ul>  
  9.     <!-- Tab panes -->  
  10.     <div class="tab-content" style="padding-top: 20px">  
  11.         <div role="tabpanel" class="tab-pane active" id="tabs-1">  
  12.             @Html.Grid(Model).Columns(columns =>  
  13.                {  
  14.                    columns.Add(foo => foo.date).Titled("Date").SetWidth(30).Sortable(true); /*BTG 11/10/2017 - old .Filterable(true)*/  
  15.                    columns.Add(foo => foo.so_no).Titled("SO No.").SetWidth(30).Sortable(true); //.Filterable(true);  
  16.                    columns.Add(foo => foo.serial).Titled("Serial").SetWidth(30).Sortable(true); //.Filterable(true);  
  17.                    columns.Add(foo => foo.status).Titled("Status").SetWidth(30).Sortable(true); //.Filterable(true);  
  18.                    columns.Add(foo => foo.technician).Titled("Technician").SetWidth(30).Sortable(true); //.Filterable(true);  
  19.                }).WithPaging(5).Named("myJob")  
  20.   
  21.         </div>  
  22.         <div role="tabpanel" class="tab-pane" id="tabs-2">  
  23.             @Html.Grid(Model).Columns(columns =>  
  24.                {  
  25.                    columns.Add(foo => foo.date).Titled("Date").SetWidth(30).Sortable(true); /*BTG 11/10/2017 - old .Filterable(true)*/  
  26.                    columns.Add(foo => foo.so_no).Titled("SO No.").SetWidth(30).Sortable(true); //.Filterable(true);  
  27.                    columns.Add(foo => foo.serial).Titled("Serial").SetWidth(30).Sortable(true); //.Filterable(true);  
  28.                    columns.Add(foo => foo.status).Titled("Status").SetWidth(30).Sortable(true); //.Filterable(true);  
  29.                    columns.Add(foo => foo.technician).Titled("Technician").SetWidth(30).Sortable(true); //.Filterable(true);  
  30.                }).WithPaging(5).Named("allJobs")  
  31.         </div>  
  32.     </div>  
  33. </div> 
 

Answers (3)