Signal R Server filtering not working

3 posts, 0 answers
  1. Lotux
    Lotux avatar
    3 posts
    Member since:
    Feb 2016

    Posted 01 Jun 2016 Link to this post


    I created a hub with the CRUD method:

    public class PayslipUploadHub : Microsoft.AspNet.SignalR.Hub
        public DataSourceResult ReadPayslipBatch([DataSourceRequest]DataSourceRequest request)
            return DAL.GetPayslipBatchHistory(null).ToDataSourceResult(request);
        public void UpdatePayslipBatch(PayslipGeneration payslipBatch)
            Clients.Others.update(new DataSourceResult
                Data = new[] { payslipBatch }
        public DataSourceResult CreatePayslipBatch(DataSourceResult payslipBatch)
            return payslipBatch;
        public void DestroyPayslipBatch(PayslipGeneration payslipBatch)
            Clients.Others.destroy(new DataSourceResult
                Data = new[] { payslipBatch }

    I need to trigger the creation and the update not directly from the grid but on other actions. So to trigger Signal R this what i do:

    var payslipBatch = DAL.GetPayslipBatchHistory(oResult.Result).First();
      using (var scope = _wa.CreateWorkContextScope(HttpContext))
         var context = scope.Resolve<Microsoft.AspNet.SignalR.Infrastructure


    When I debug this it actually never break into the CreatePayslipBatch Method of the Hub, and I don't understand why.

    Here is the grid declaration:

            .Columns(columns =>
                columns.Bound(c => c.Status.Code).Width(60).ClientTemplate("<i class='#=Status.Class#'></i>").HtmlAttributes(new { style = "text-align:center" }).Title("Status");
                columns.Bound(c => c.Name).Width(250);
                columns.Bound(c => c.Period).Format("{0:MMMM yyyy}").Width(110);
                columns.Bound(c => c.StatusInfo);
                columns.Bound(c => c.Comment);
                columns.Bound(c => c.CreatedBy).Width(140);
                columns.Bound(c => c.CreatedOn).Format("{0:dd MMM yyyy}").Width(110).Title("Created On");
                columns.Bound(c => c.UpdatedBy).Width(140);
                columns.Bound(c => c.UpdatedOn).Format("{0:dd MMM yyyy}").Width(110).Title("Updated On");
                columns.Template(e => { }).ClientTemplate(
                    "# if(Status.Code == 'FAILED') " +
                                   "{# <a onclick = 'RegenFailed( #: data.Id # );'><i title='Regenerate Payslip' class='fa fa-undo fa-2x'></i></a> #} " +
                                   "else {# <i title='Regenerate Payslip' class='fa fa-undo fa-2x'></i> #}#")
                                   .Title("").Width(50).HtmlAttributes(new { style = "text-align:center" });
                //columns.Command(command => command.Custom("Delete").Click("DeleteBatchLine")).Title("").Width(80);
                //columns.Command(command => command.Custom("Check").Click("CheckBatchLine")).Title("").Width(80);
            .HtmlAttributes(new { style = "height: 380px;" })
            .Pageable(pageable => pageable
                .PageSizes(new List<string>{"10","20","50"})
           .DataSource(dataSource => dataSource
            .Events(ev => ev.RequestEnd("onRequestEnd"))
            .Sort(s => s.Add("CreatedOn").Descending())
            .Transport(tr => tr
                .Client(c => c
                .Server(s => s
            .Schema(schema => schema
                .Model(model =>
            .Events(e => e.DataBound("onDataBound"))


    At the beginning I was not using the DataSourceResult but directly the type PayslipGeneration and I had a lot of trouble with the pagination. So i converted the read function to return a DataSourceResult and then it broke all the other CRUD method I tried to cast the other CRUD method to  work only with DataSourceResult as mention on this post, but it still not working.

    Any idea?




  2. Lotux
    Lotux avatar
    3 posts
    Member since:
    Feb 2016

    Posted 01 Jun 2016 in reply to Lotux Link to this post

    Sorry actually the create of the in the hub is like this:

    public DataSourceResult CreatePayslipBatch(PayslipGeneration payslipBatch)
        Clients.Others.create(new DataSourceResult
            Data = new[] { payslipBatch }
        return new DataSourceResult
            Data = new[] {payslipBatch}

  3. Daniel
    Daniel avatar
    2231 posts

    Posted 06 Jun 2016 Link to this post


    I am not sure if I understand correctly the issue but the server CreatePayslipBatch method should not be called as result of calling the client createPayslipBatch method:
    The server method should only be called when the create action is triggered by the client. Otherwise you will get infinite loop when calling the client from the server methods.

    Also, note that the data passed to the client should have the same structure so you should change the code to pass a DataSourceResult when calling all clients:
    context.Clients.All.createPayslipBatch(new DataSourceResult
        Data = new[] { payslipBatch }

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top