Hi SyncFusion,
I am trying to enable sorting/filtering on a grid of data. My grid code looks like this:
@using App.Models
@using Syncfusion.EJ2.Blazor.Data
@using Syncfusion.EJ2.Blazor.Grids
<EjsGrid TValue="@Files" AllowSorting="true" AllowMultiSorting="true" AllowFiltering="true" AllowGrouping="true" Height="650" Width="auto">
<EjsDataManager Url="api/Files" Adaptor="Adaptors.WebApiAdaptor"></EjsDataManager>
<GridColumns>
<GridColumn Field="FileId" HeaderText="FileId" TextAlign="TextAlign.Right" AllowSorting="true"></GridColumn>
<GridColumn Field="FileName" HeaderText="FileName" TextAlign="TextAlign.Right" AllowSorting="true"></GridColumn>
<GridColumn Field="DateImported" HeaderText="DateImported" Format="yMd" Type="ColumnType.Date" AllowSorting="true"></GridColumn>
</GridColumns>
</EjsGrid>
Which calls the following controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using App.Models;
using App.Shared.DataAccess;
using Microsoft.Extensions.Primitives;
namespace App.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class FilesController : ControllerBase
{
//Copied from https://ej2.syncfusion.com/blazor/documentation/grid/data-binding/ tutorial
FileAccessLayer db = new FileAccessLayer();
[HttpGet]
public object Get()
{
IQueryable<Files> data = db.DbGet().AsQueryable();
var count = data.Count();
var queryString = Request.Query;
if (queryString.Keys.Contains("$inlinecount"))
{
StringValues Skip;
StringValues Take;
int skip = (queryString.TryGetValue("$skip", out Skip)) ? Convert.ToInt32(Skip[0]) : 0;
int top = (queryString.TryGetValue("$top", out Take)) ? Convert.ToInt32(Take[0]) : data.Count();
return new { Items = data.Skip(skip).Take(top), Count = count };
}
else
{
return data;
}
}
}
}
Which in turn asks for the following methods from FileAccessLayer:
public class FileAccessLayer
{
DataTableContext db = new DataTableContext();
public DbSet<Files> DbGet()
{
try
{
return db.Files;
}
catch
{
throw;
}
}
}
Which in turn calls a standard entity framework scaffolded context and model, called DataTableContext and Files.
The issue I am having is that the data will display fine in the table, but will not sort or filter with the sort and filter toggles. Can you please show me how to enable these features, I have had a good trawl through the forums but none of the solutions existing already seem to be directly useful.
Thank you very much
Tom