Hello,
I'm struggling to figure out why the data for the grid isn't showing up. The Grid says: No records to display.
The generated JavaScript but shows that the data was "found" as I unterstand it. I think I have done everything correct and I don't see what's the problem.
TagHelper Code:
<ejs-grid allowPaging="true"
id="audienceGrid"
actionFailure="failure"
actionBegin="begin"
actionComplete="completed"
toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel","Search" })">
<e-data-manager data="@Model"
insertUrl="@Url.Action("Add", "Audience")"
removeUrl="@Url.Action("Delete", "Audience")"
updateUrl="@Url.Action("Edit", "Audience")">
</e-data-manager>
<e-grid-pagesettings pageSize="10"></e-grid-pagesettings>
<e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editsettings>
<e-grid-columns>
<e-grid-column isIdentity="true" field="@nameof(TargetAudianceDto.Id)" headerText="Id"></e-grid-column>
<e-grid-column field="@nameof(TargetAudianceDto.Audience)" headerText="Audience"></e-grid-column>
</e-grid-columns>
</ejs-grid>
Generated JavaScript from TagHelper:
new ejs.grids.Grid({
"allowPaging": true,
"columns": [
{
"field": "Id",
"headerText": "Id",
"isIdentity": true
},
{
"field": "Audience",
"headerText": "Audience"
}
],
"dataSource": new ejs.data.DataManager({
"insertUrl": "/management/audience/add",
"removeUrl": "/management/audience/delete",
"updateUrl": "/audience/edit",
"data": [
{
"Id": 1,
"Audience": "Family"
},
{
"Id": 2,
"Audience": "Kids"
},
{
"Id": 3,
"Audience": "Men"
},
{
"Id": 4,
"Audience": "Women"
},
{
"Id": 5,
"Audience": "Adults"
}
]
}),
"editSettings": {
"allowAdding": true,
"allowDeleting": true,
"allowEditing": true,
"mode": "Dialog"
},
"ej2StatePersistenceVersion": "default version",
"frozenColumns": 0.0,
"frozenRows": 0.0,
"pageSettings": {
"currentPage": 1.0,
"pageCount": 8.0,
"pageSize": 10.0
},
"selectedRowIndex": -1.0,
"toolbar": [
"Add",
"Edit",
"Delete",
"Update",
"Cancel",
"Search"
],
"actionBegin": begin,
"actionComplete": completed,
"actionFailure": failure
}).appendTo("#audienceGrid");
|
<e-data-manager json="@Model"
insertUrl="@Url.Action("Add", "Audience")"
removeUrl="@Url.Action("Delete", "Audience")"
updateUrl="@Url.Action("Edit", "Audience")"
adaptor=”RemoteSaveAdaptor”>
</e-data-manager> |
Thank you very, very much, it worked. Wish you a good day and hopefully a happy new year. Thanks
Hello Balaji,
sorry to bother you again, but now I have an weird problem that the grid doesn't send the data if I use for example the insert method... It's null and if I look into the post header via developer tools I don't find data send, but the grid knows the correct url~
Could you please help me out there too? The code is the same with your changes using json and the adapter now.
My add method looks like this g is always null currently:
public IActionResult Add([FromBody] SyncfusionOperationModel<TargetAudianceDto> g)
{
_taRepo.Add(g.Value);
return Json(g.Value);
}
and the crud model I use is from your sample projects (just renamed a little bit^^):
public class SyncfusionOperationModel<T> where T : class
{
[JsonProperty("action")]
public string Action { get; set; }
[JsonProperty("table")]
public string Table { get; set; }
[JsonProperty("keyColumn")]
public string KeyColumn { get; set; }
[JsonProperty("key")]
public object Key { get; set; }
[JsonProperty("value")]
public T Value { get; set; }
[JsonProperty("added")]
public IList<T> Added { get; set; }
[JsonProperty("changed")]
public IList<T> Changed { get; set; }
[JsonProperty("deleted")]
public IList<T> Deleted { get; set; }
[JsonProperty("params")]
public IDictionary<string, object> @params { get; set; }
}
|
[HomeController.cs]
//insert the record
public ActionResult Insert([FromBody]CRUDModel<OrdersDetails> value) // get the parameters in value property so use property value instead of “g”
{
OrdersDetails.GetAllRecords().Insert(0, value.value);
return Json(value);
} |
Hello Balaji,
sadly that didin't help. The main cause is somehow that there's no data in the sent header.
I've copied the post request that the grid sends to the server, you'll see that there's no data from:
:authority: localhost:44335
:method: POST
:path: /management/audience/add
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: ja,de-DE;q=0.9,de;q=0.8,en-US;q=0.7,en;q=0.6
cache-control: no-cache
content-length: 57
content-type: application/json; charset=UTF-8
cookie: .AspNetCore.Antiforgery
dnt: 1
origin: https://localhost:44335
pragma: no-cache
referer: https://localhost:44335/management/audiance
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="98", "Microsoft Edge";v="98"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4741.0 Safari/537.36 Edg/98.0.1100.3
|
public class BigData
{
---
public int? OrderID { get; set; }
public string Id { get; set; }
public int? N1 { get; set; }
----
public double? Freight { get; set; }
public DateTime? OrderDate { get; set; }
---
}
|
|
|
Okay, now after I marked the string Property as Nullable (I use .NET 6 were Nullable Context is enabled by default ) it worked... Thank you haven't thought that this could even be a problem, but now I know of I'll pay attention to that. Thank you very much and wish you and your team a happy new year.