I am trying to bind it with dynamic columns SQL table paging. The issue is on the second scroll/page it failed the method.
Razor Page
@model System.Data.DataTable
@(Html.Kendo().Grid<dynamic>()
.Name("Grid")
.Sortable()
.Scrollable(sc => sc.Endless(true))
.Filterable()
.Groupable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(100)
.Model(model =>
{
var id = "Id";
model.Id(id);
})
.Read(read => read.Action("Data_Read", "DynamicColumn"))
)
)
Controller DynamicColumn
public IActionResult Data_Read([DataSourceRequest] DataSourceRequest request)
{
var dt = GetViewsData(request.PageSize, request.Page);
var data = dt.ToDataSourceResult(request);
var viewData = new DataSourceResult()
{
Data = data.Data, //this return NULL on the second page/scroll request
Total = 181480 //total rows of table, just make it static
};
return Json(viewData);
}
public DataTable GetViewsData(int pageSize, int page)
{
try
{
int offSet = (page - 1) * 100;
string connString = "Server=.; Database=TheVault_VMC; Trusted_Connection=true; MultipleActiveResultSets=True; Encrypt=False;";
SqlConnection con = new SqlConnection(connString);
con.Open();
SqlCommand cmd = new SqlCommand("sp_GetData", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@OFFSetRows", offSet);
cmd.Parameters.AddWithValue("@PageSize", pageSize);
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
var dataTable = new DataTable();
dataAdapter.Fill(dataTable);
dataAdapter.FillSchema(dataTable, SchemaType.Mapped);
con.Close();
return dataTable;
}
catch (Exception ex)
{
throw ex;
}
}
}
SQL Server Procedure
CREATE PROCEDURE [dbo].[sp_GetData]
@OFFSetRows INT,
@PageSize INT
As
BEGIN
SELECT Id, [Column1], [Column2], [Column3],[Column4],[Column5],[Column6]
FROM
[StagingDetail]
ORDER BY Id
OFFSET @OFFSetRows ROWS
FETCH NEXT @PageSize ROWS ONLY
END
The issue is the function ToDataSourceResult() returns NULL Data on the second request