This is a migrated thread and some comments may be shown as answers.

Signal R Server filtering not working

2 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lotux
Top achievements
Rank 1
Lotux asked on 01 Jun 2016, 04:49 PM

Hi, 

I created a hub with the CRUD method:

[Microsoft.AspNet.SignalR.Hubs.HubName("PayslipUploadHub")]
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)
    {
 
        Clients.Others.create(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
                   .IConnectionManager>().GetHubContext<PayslipUploadHub>();
     context.Clients.All.createPayslipBatch(payslipBatch);
 }

 

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:

@(Html.Kendo().Grid<PayslipGeneration>()
        .Name("PayslipGenerationHistory")
        .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;" })
        .Scrollable()
        .Groupable()
        .Sortable()
        .ClientDetailTemplateId("template")
        .Pageable(pageable => pageable
            .Refresh(true)
            .PageSizes(new List<string>{"10","20","50"})
            )
       .DataSource(dataSource => dataSource
        .SignalR()
        .PageSize(10)
        .Events(ev => ev.RequestEnd("onRequestEnd"))
        .AutoSync(true)
        .ServerFiltering(true)
        .ServerPaging(true)
        .Sort(s => s.Add("CreatedOn").Descending())
        .Transport(tr => tr
            .Promise("hubStart")
            .Hub("hub")
            .Client(c => c
                    .Read("readPayslipBatch")
                    .Update("updatePayslipBatch")
                    .Create("createPayslipBatch")
                    .Destroy("destroyPayslipBatch"))
            .Server(s => s
                    .Read("ReadPayslipBatch")
                    .Update("UpdatePayslipBatch")
                    .Create("CreatePayslipBatch")
                    .Destroy("DestroyPayslipBatch")))
        .Schema(schema => schema
            .Data("Data")
            .Total("Total")
            .Aggregates("Aggregates")
            .Model(model =>
            {
                model.Id("Id");
            }
            )))
        .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 Answers, 1 is accepted

Sort by
0
Lotux
Top achievements
Rank 1
answered on 01 Jun 2016, 04:53 PM

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}
    };
}

0
Daniel
Telerik team
answered on 06 Jun 2016, 06:52 AM
Hello,

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:
context.Clients.All.createPayslipBatch(payslipBatch);
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 }
});


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Lotux
Top achievements
Rank 1
Answers by
Lotux
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or