0

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?

1
  • can you please provide some code so that we can check your dataSource ? Commented Feb 19, 2014 at 7:08

2 Answers 2

1

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.
Sign up to request clarification or add additional context in comments.

8 Comments

What you're mean is i dont need two script one for AllNotifications and another for NewNotifications ? what about my method ? can you explain me more about this please?
Yes, you can combine them together as a view model + To signal users about the new changes from server, it's better to use SignalR and not just querying the server every 8 seconds. SignalR is much more efficient for these kinds for tasks.
Thanks,,i confuse abit:( about my method i write two method with StoredProcedure one of them give use All notification and the other one is new notification with where condition uncheck=true, i write webmethod method, i should make change on these methods and SP or not??
no. you have 2 properties here in MyReportViewModel. create a new instance of it and return it as a json. also you can apply caching for the all rows parts as well (server side).
I should read notification from my DataBase! how can i can do it?? sorry, I really confused
|
0

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.! :)

2 Comments

Thanks for your answering.. if its not a good way.. may you advice me a better wat please?
It's not a Grid. Its a DataSource component

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.