In several of the examples (https://ej2.syncfusion.com/aspnetmvc/documentation/grid/data-binding/#remote-save-adaptor ) I see EditableOrder as a type, but it says not defined, and I haven't been able to figure out where it's at so I can include the library.
I don't need a whole project, just the name of the library to import so that EditableOrder is defined.
Thanks
public ActionResult Insert(CRUDModel Object)
{
var ord = Object.Value;
OrdersDetails.GetAllRecords().Insert(0, ord);
return Json(Object.Value);
}
public class CRUDModel
{
public List<OrdersDetails> Added { get; set; }
public List<OrdersDetails> Changed { get; set; }
public List<OrdersDetails> Deleted { get; set; }
public OrdersDetails Value { get; set; }
public int key { get; set; }
public string action { get; set; }
} |
Ok, that all makes sense now, and I put that in, but when I go to add a new line, or update an existing line, the Value is nothing (like null).
index.vbhtml:
@Html.EJS().Grid("Grid").DataSource(Function(datamanager As DataManagerBuilder) ({datamanager.Json(ViewBag.DataSource.ToArray()).InsertUrl("/Home/Insert").RemoveUrl("/Home/Delete").UpdateUrl("/Home/Update").Adaptor("RemoteSaveAdaptor")})).Columns(Function(col As Object) {
col.Field("JobCardLineID").HeaderText("ID").IsPrimaryKey(True).Visible(False).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(),
col.Field("LineNum").HeaderText("Line Num").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(),
col.Field("TotalAmt").HeaderText("Total Amount").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(),
col.Field("StatusType").HeaderText("Status Type").Edit(New With {.create = "createStatusType", .read = "readStatusType", .destroy = "destroyStatusType", .write = "writeStatusType"}).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).Add(),
col.Field("LineDate").HeaderText("Line Date").Format("M/d/y").Edit(New With {.create = "createLineDate", .read = "readLineDate", .destroy = "destroyLineDate", .write = "writeLineDate"}).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(),
col.Field("Notes").HeaderText("Notes").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).Add(),
col.Field("Adjustment").HeaderText("Adjustment?").Edit(New With {.create = "createAdjustment", .read = "readAdjustment", .destroy = "destroyAdjustment", .write = "writeAdjustment"}).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add(),
col.Field("ZeroDollar").HeaderText("Zero Dollar?").Edit(New With {.create = "createZeroDollar", .read = "readZeroDollar", .destroy = "destroyZeroDollar", .write = "writeZeroDollar"}).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add()
}).EditSettings(Function(edit) {edit.AllowAdding(True).AllowEditing(True).AllowDeleting(True).Mode(Syncfusion.EJ2.Grids.EditMode.Normal)}).Toolbar(New List(Of String)({"Add", "Edit", "Delete", "Update", "Cancel"})).Render();
HomeController.vb:
Public Function Update(<Microsoft.AspNetCore.Mvc.FromBody> value As iCRUDModel(Of JCLine)) As Mvc.ActionResult
Try
Dim jcl As JCLine = value.value
Dim line As JCLine = lines.Where(Function(x) (x.JobCardLineID = jcl.JobCardLineID))
line.LineNum = jcl.LineNum
line.TotalAmt = jcl.TotalAmt
line.StatusType = jcl.StatusType
line.LineDate = jcl.LineDate
line.Notes = jcl.Notes
line.Adjustment = jcl.Adjustment
line.ZeroDollar = jcl.ZeroDollar
Return Json(lines)
Catch ex As Exception
Return Json(ex.Message)
End Try
End Function
Public Function Insert(<FromBody> value As CRUDModel) As Mvc.ActionResult
Return Json(lines)
End Function
When I push the update button, this is the request payload that gets sent out:
{"value":{"JobCardLineID":23,"LineNum":"1","TotalAmt":"$67.40","StatusType":"Paid","LineDate":"2012-07-19T04:00:00.000Z","Notes":"","Adjustment":false,"ZeroDollar":false},"action":"update","keyColumn":"JobCardLineID","key":23}
Also, my CRUDModel classes:
Public Class CRUDModel
Public Property Added As List(Of JCLine)
Public Property Changed As List(Of JCLine)
Public Property Deleted As List(Of JCLine)
Public Property Value As JCLine
Public Property key As Integer
Public Property action As String
End Class
Public Class iCRUDModel(Of T)
Public Property action As String
Public Property table As String
Public Property keyColumn As String
Public Property key As Object
Public Property value As T
Public Property added As List(Of T)
Public Property changed As List(Of T)
Public Property deleted As List(Of T)
Public Property params As IDictionary(Of String, Object)
End Class
<div class="control-section">
@Html.EJS().Grid("Grid").DataSource(ds => ds.Url("/Home/UrlDatasource")
.Adaptor("UrlAdaptor").InsertUrl("/Home/Insert").RemoveUrl("/Home/Remove").UpdateUrl("/Home/Update")).Columns(col =>
{
. . .Render()
</div>
|
Namespace mvc_ej2.Controllers
Public Class HomeController
Inherits Controller
Public Shared orddata As List(Of OrdersDetails) = New List(Of OrdersDetails)()
Public Function Index() As ActionResult
If orddata.Count() = 0 Then BindData()
ViewBag.datasource = orddata.ToArray()
Return View()
End Function
Public Sub BindData()
Dim code As Integer = 10000
For i As Integer = 1 To 10 - 1
Call orddata.Add(New OrdersDetails(code + 2, "ANATR", i + 0, 3.3 * i, True, New DateTime(1995, 7, 2, 2, 3, 5), "Madrid", "Queen Cozinha", "Brazil", New DateTime(1996, 9, 11), "Avda. Azteca 123"))
Call orddata.Add(New OrdersDetails(code + 3, "ANTON", i + 1, 4.3 * i, True, New DateTime(2012, 12, 25, 2, 3, 5), "Cholchester", "Frankenversand", "Germany", New DateTime(1996, 10, 7), "Carrera 52 con Ave. Bolívar #65-98 Llano Largo"))
Call orddata.Add(New OrdersDetails(code + 4, "BLONP", i + 2, 5.3 * i, False, New DateTime(2002, 12, 25, 2, 3, 5), "Marseille", "Ernst Handel", "Austria", New DateTime(1996, 12, 30), "Magazinweg 7"))
Call orddata.Add(New OrdersDetails(code + 5, "BOLID", i + 3, 6.3 * i, True, New DateTime(1953, 02, 18, 05, 2, 4), "Tsawassen", "Hanari Carnes", "Switzerland", New DateTime(1997, 12, 3), "1029 - 12th Ave. S."))
code += 5
Next
End Sub
Public Function UrlDatasource(ByVal dm As TestDm) As ActionResult
Dim DataSource As IEnumerable = orddata.ToList()
Dim operation As DataOperations = New DataOperations()
If dm.Search IsNot Nothing AndAlso dm.Search.Count > 0 Then
DataSource = operation.PerformSearching(DataSource, dm.Search) 'Search
End If
If dm.Sorted IsNot Nothing AndAlso dm.Sorted.Count > 0 Then 'Sorting
DataSource = operation.PerformSorting(DataSource, dm.Sorted)
End If
If dm.Where IsNot Nothing AndAlso dm.Where.Count > 0 Then 'Filtering
DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where(0).[Operator])
End If
Dim count As Integer = DataSource.Cast(Of OrdersDetails)().Count()
If dm.Skip <> 0 Then
DataSource = operation.PerformSkip(DataSource, dm.Skip) 'Paging
End If
If dm.Take <> 0 Then
DataSource = operation.PerformTake(DataSource, dm.Take)
End If
Return If(dm.RequiresCounts, Json(New With {
.result = DataSource,
count
}), Json(DataSource))
End Function
Public Function Update(ByVal myObject As CRUDModel(Of OrdersDetails)) As ActionResult
Dim ord = myObject
Dim val As OrdersDetails = orddata.Where(Function([or]) CBool([or].OrderID Is ord.Value.OrderID)).FirstOrDefault()
If val IsNot Nothing Then
val.OrderID = ord.Value.OrderID
val.EmployeeID = ord.Value.EmployeeID
val.CustomerID = ord.Value.CustomerID
val.Freight = ord.Value.Freight
val.OrderDate = ord.Value.OrderDate
val.ShipCity = ord.Value.ShipCity
val.ShipAddress = ord.Value.ShipAddress
val.ShippedDate = ord.Value.ShippedDate
End If
Return Json(ord.Value)
End Function
Public Function Insert(ByVal value As OrdersDetails) As ActionResult
Dim ord = value
orddata.Insert(0, ord)
Return Json(value)
End Function
Public Sub Remove(ByVal key As Integer)
Call orddata.Remove(orddata.Where(Function([or]) [or].OrderID = key).FirstOrDefault())
End Sub
Public Class TestDm
Inherits DataManagerRequest
Public Property flag As Integer
End Class
Public Class CRUDModel
Public Property value As OrdersDetails
Public Property key As Integer
Public Property action As String
Public Property keycolumn As String
End Class
Public Class OrdersDetails
Public Sub New()
End Sub
Public Sub New(ByVal OrderID As Integer, ByVal CustomerId As String, ByVal EmployeeId As Integer, ByVal Freight As Double, ByVal Verified As Boolean, ByVal OrderDate As Date, ByVal ShipCity As String, ByVal ShipName As String, ByVal ShipCountry As String, ByVal ShippedDate As Date, ByVal ShipAddress As String)
Me.OrderID = OrderID
Me.CustomerID = CustomerId
Me.EmployeeID = EmployeeId
Me.Freight = Freight
Me.ShipCity = ShipCity
Me.Verified = Verified
Me.OrderDate = OrderDate
Me.ShipName = ShipName
Me.ShipCountry = ShipCountry
Me.ShippedDate = ShippedDate
Me.ShipAddress = ShipAddress
End Sub
Public Property OrderID As Integer?
Public Property CustomerID As String
Public Property EmployeeID As Integer?
Public Property Freight As Double?
Public Property ShipCity As String
Public Property Verified As Boolean
Public Property OrderDate As Date
Public Property ShipName As String
Public Property ShipCountry As String
Public Property ShippedDate As Date
Public Property ShipAddress As String
End Class
End Class
End Namespace |