I am developing a Kendo grid using SignalR, this grid is only to read de data, and other enviroment is creating new lines and the hub raise this create method.
It is working fine without .ServerPaging(true), .ServerFiltering(true), .ServerSorting(true)
@(Html.Kendo().Grid<StatScanModeHubModel>() .Name("Grid") .Pageable(a=>a
.PageSizes(new []{100,200,500}) .Refresh(true)) .Navigatable() .Sortable() .Filterable() .DataSource(dataSource => dataSource
.SignalR() .ServerPaging(true) .ServerFiltering(true) .ServerSorting(true) .Sort(sort => sort.Add(a => a.Created).Descending()) .PageSize(100) .Transport(tr => tr
.Promise("hubStart") .Hub("hub") .Client(c => c .Read("read") .Create("create")) .Server(s => s .Read("read") .Create("create")) ) .Schema(schema => schema .Model(model => model.Id(a => a.StatScanModeId)) ) )
Hub Code: public class StatScanModeHub : Hub {
public string Read([DataSourceRequest]DataSourceRequest request) { DataSourceResult returnList;
using (var managerService = new ManagerService()) { var results = managerService.StatScanModeManager.GetAll(); returnList = results.ToDataSourceResult(request, Mapper.Map<StatScanMode, StatScanModeHubModel>); //returnList = Mapper.Map<IEnumerable<StatScanMode>, IEnumerable<StatScanModeHubModel>>(results2); } return Newtonsoft.Json.JsonConvert.SerializeObject(returnList); }
public StatScanModeHubModel Create(StatScanModeHubModel statScanMode) { Clients.Others.create(statScanMode); return statScanMode; }
But when I activate .ServerPaging(true), .ServerFiltering(true), .ServerSorting(true)In the Hub, the parameter request does not recieve the data to filter, sort... only tha paging parameter.
Please could someone help me to guide about how I can develop this functionality?
8 Answers, 1 is accepted
Hello,
I am developing a Kendo grid using SignalR, this grid is only to read de data, and other enviroment is creating new lines and the hub raise this create method.
It is working fine without .ServerPaging(true), .ServerFiltering(true), .ServerSorting(true)
@(Html.Kendo().Grid<
StatScanModeHubModel
>()
.Name("Grid")
.Pageable(a=>a
.PageSizes(new []{100,200,500})
.Refresh(true))
.Navigatable()
.Sortable()
.Filterable()
.DataSource(dataSource => dataSource
.SignalR()
.ServerPaging(true)
.ServerFiltering(true)
.ServerSorting(true)
.Sort(sort => sort.Add(a => a.Created).Descending())
.PageSize(100)
.Transport(tr => tr
.Promise("hubStart")
.Hub("hub")
.Client(c => c
.Read("read")
.Create("create"))
.Server(s => s
.Read("read")
.Create("create"))
)
.Schema(schema => schema
.Model(model => model.Id(a => a.StatScanModeId))
)
)
public class StatScanModeHub : Hub
{
public string Read([DataSourceRequest]DataSourceRequest request)
{
DataSourceResult returnList;
using (var managerService = new ManagerService())
{
var results = managerService.StatScanModeManager.GetAll();
returnList = results.ToDataSourceResult(request,
Mapper.Map<
StatScanMode
, StatScanModeHubModel>);
//returnList = Mapper.Map<
IEnumerable
<StatScanMode>, IEnumerable<
StatScanModeHubModel
>>(results2);
}
return Newtonsoft.Json.JsonConvert.SerializeObject(returnList);
}
public StatScanModeHubModel Create(StatScanModeHubModel statScanMode)
{
Clients.Others.create(statScanMode);
return statScanMode;
}
Please could someone help me to guide about how I can develop this functionality?
For convenience I created small example which demonstrates how to implement SignalR binding with server operations using the Kendo.DynamicLinq - you can find it attached to the current thread.
Regards,
Vladimir Iliev
Telerik
I have had a play with this sample, but I dont see how you would adjust the filter to take value dynamically from the page, eg an edit box, in the line
.Filter(f => f.Add(m => m.UnitPrice).IsGreaterThanOrEqualTo(10))
what if you dont want 10 hard coded?
In the AJAX implementation, there is a Data() function on the CrudOperation that can run javascript.
The result of which gets passed into the method on the Controller method. Very flexible and powerful. Could that be provided for the SignalR implementation?
Thanks
Greg
In the Grid MVC wrapper you can define custom "parameterMap" function in which to include the desired additional parameters back to the server side. Please check the example below:
.Transport(tr => tr
.ParameterMap(
"parameterMap"
)
.Promise(
"hubStart"
)
.Hub(
"hub"
)
.Client(c => c
function
parameterMap(data, type) {
if
(type ===
"read"
) {
data.filter = { logic:
"and"
, filters: [{ field:
"UnitPrice"
, operator:
"eq"
, value: 10 }] };
}
return
data;
}
Regards,
Vladimir Iliev
Telerik
Sorry for resurrecting this old thread, but I have wasted a ton of time today trying to figure out something related to this.
Sorting does NOT work in the example you uploaded. If I put a breakpoint on the hub function, then i always get NULL for sorting.
PS: i did add .ServerSorting(true)...
I tried to reproduce the described behavior but everything is working as expected on our side as seen in this screencast. Could you please elaborate more on what is the exact configuration that you are using and how to reproduce the described behavior on our side?
Regards,
Vladimir Iliev
Telerik
Sorry for bringing this thread back from the dead.
Your example is the only one I could find that has Razor syntax for the signalR grid however there are some issues I am facing:
The link on the main page to open another browser window instead opens a window which says unknown protocol.
The Update/Delete/Create methods do not work with two instances of the browser open. I am using Firefox latest stable version (41).
Please let me know how to fix this as I am attempting to implement signalR via Razor syntax in an app I am working on.
ThanksPlease check the answers of your questions below:
1) To fix the link issue remove the "href" attribute text
2) The Update / Destroy / Create actions are not working due to invalid configuration (thank you for noting this). Please check the updated methods below:
public
void
Update(ProductViewModel product)
{
productService.Update(product);
Clients.Others.update(
new
{Data =
new
List<ProductViewModel>() { product } });
}
public
void
Destroy(ProductViewModel product)
{
productService.Destroy(product);
Clients.Others.destroy(
new
{ Data =
new
List<ProductViewModel>() { product } });
}
public
Object Create(ProductViewModel product)
{
productService.Create(product);
Clients.Others.create(
new
{ Data =
new
List<ProductViewModel>() { product } });
return
new
{ Data =
new
List<ProductViewModel>() { product } };
}
Regards,
Vladimir Iliev
Telerik