how to update the data of dataSource

3 posts, 1 answers
  1. Ikou
    Ikou avatar
    12 posts
    Member since:
    Aug 2015

    Posted 19 Oct 2015 Link to this post

    Hello,

     

    I want to mass update the data of dataSource in JSON.
    If you run in the following way, it seems well data is not set.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>Kendo UI Snippet</title>
     
     
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    </head>
    <body>
       
    <div id="gantt"></div>
    <script>
       
      var dataSource =new kendo.data.GanttDataSource({
        data: [
          {
            "id": 0,
            "orderId": 0,
            "parentId": null,
            "title": "old task1",
            "start": "2015-10-19",
            "end": "2015-10-20"
          },
          {
            "id": 1,
            "orderId": 0,
            "parentId": null,
            "title": "old task2",
            "start": "2015-10-19",
            "end": "2015-10-20"
           }
          ]
      });
       
    $("#gantt").kendoGantt({
      dataSource: dataSource,
      views: ["week"],
      columns: [
        { field: "title", title: "Title" },
        { field: "id", title: "ID" }
      ]
    });
       
    dataSource.fetch(function(){
      dataSource.data([
        {
          "id": 0,
          "orderId": 0,
          "parentId": null,
          "title": "new task1",
          "start": "2015-10-19",
          "end": "2015-10-20"
        },
        {
          "id": 1,
          "orderId": 0,
          "parentId": null,
          "title": "new task2",
          "start": "2015-10-19",
          "end": "2015-10-20"
        }
      ]);
    });
       
    </script>
    </body>
    </html>

     

    Date is not displayed well as attached image.

     

  2. Answer
    Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 21 Oct 2015 Link to this post

    Hello,

    In order to change the content of the data source, the appropriate approach would be to use the setDataSource method and pass a new instance of the data source containing the new data. Here is a dojo snippet. The fetch method is used to fetch data from a remote service as stated in our online documentation.

    Regards,
    Dimitar Terziev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Ikou
    Ikou avatar
    12 posts
    Member since:
    Aug 2015

    Posted 21 Oct 2015 in reply to Dimitar Terziev Link to this post

    Well I was able to understand.
    Thank you!
Back to Top