pmn
pmn

Reputation: 2255

KendoUI Datasource Component

I wrote two functions,assume that one of them get us list of all notifications and one of them get new notification, i wrote a script which call first method and get list of all notifications in Json format, and write another script which call second method every 8 second, and get us new notifications in Json format too. i show these notifacations in a KendoUI Datasource. so i have two datasource for just one KendoUI Datasource component, i want to add two data source in one datasource, is there any way to do this?

EDIT: This is my code

 <script id="template" type="text/x-kendo-template">
             
          <tr>

            <td>#= ID #</td>
            <td>#= TITLE #</td>
            <td>#= DESC #</td>
               
           </tr>
  </script>

My first script which get us list of all notification :

       var datas = function () {

                        var objects = [];
                        $.ajax({
                            type: "POST",
                            url: "./WebForm1.aspx/GetNoti",
                            data: {},
                            async: false,
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success:
                                function (response) {

                                    for (var i = 0; i < response.d.length; i++) {

                                        objects.push({ 'ID': response.d[i].ID, 'TITLE': response.d[i].TITLE, 'DESC': response.d[i].DESC });

                                    }
                                },

                        });
                        return objects;
                    };




                    var dataSource = new kendo.data.DataSource({
                        data: datas(),
                        change: function () {
                            $("#movies tbody").html(kendo.render(template, this.view()));
                        }
                    });

                   dataSource.read();

and this is my seccond script which call method that give us new notifications every 8 sec:

     $("#go").click(function () {
                        setInterval(
                            function () { test2();}, 8000);
                    });

        var p = function () {
                        var objects = [];
                        $.ajax({
                            type: "POST",
                            url: "./WebForm1.aspx/GetUnCheckNotification",
                            data: {},
                            async: false,
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success:
                                function (response) {

                                    for (var i = 0; i < response.d.length; i++) {

                                        objects.push({ 'ID': response.d[i].ID, 'TITLE': response.d[i].TITLE, 'DESC': response.d[i].DESC });

                                    }
                                },

                        });
                        return objects;

                    };

          function test2() {

                        var dataSource2 = new kendo.data.DataSource({
                            data: p(),
                            change: function () {
                                $("#movies tbody").html(kendo.render(template, this.view()));
                            }

                        });
                        dataSource2.read();

                    }

Now i want some thing like this :

dataSource = dataSource + dataSource2

dataSource.read();

Is there anyway?

Upvotes: 0

Views: 348

Answers (2)

VahidN
VahidN

Reputation: 19186

JSON format cab be a nested structure. Define a view model and then use it.

public class Report
{
    public int Id {set; get;}
    public string Title {set; get;}
    public string Desc {set; get;}
}

public class MyReportViewModel
{
  public List<Report> NewNotifications {set;get;}
  public List<Report> AllNotifications {set;get;}
}
  • Then serialize this new MyReportViewModel { ... } using Json.NET library (server side).
  • On the client side, you can use the returned JSON format as usual.

Upvotes: 1

Vivek Parekh
Vivek Parekh

Reputation: 1085

Never tried anything like this. But when I was looking for your answer, I found this link at Telerik Forums.

Two Data Sources, One Grid

This might help.! :)

Upvotes: 0

Related Questions