ListView add new item(s)

2 posts, 0 answers
  1. Norman
    Norman avatar
    3 posts
    Member since:
    Jul 2011

    Posted 14 Jan 2013 Link to this post

    Hello,

    i've searchd for a way to add new items to a exsisitng ListView without reading the DataSoucre again.

    I want to add one or more complete filled items to the exisiting ListView that have a DataSource the question is how should i do that?

    Sample-Code:
    var objectListDataSource = new kendo.data.DataSource( {
                   transport: {
                       read: function ( options ) {
                           $.ajax( {
                               url: '/default/GetUsers',
                               type: 'POST',
                               dataType: 'json',
                               data: { ids: ids },
                               traditional: true,
                               success: function ( data ) {
                                   options.success( data );
                               }
                           } );
                       }
                   },
                   schema: {
                       data: 'items',
                       model: {
                           id: 'ID',
                           fields: {
                               ID: { type: "Number", editable: false, nullable: false, validation: { required: false} },
                               UserName: "UserName"
                           }
                       }
                   }
               } );
     
               $( '#objectList' ).kendoListView( {
                   dataSource: objectListDataSource,
                   template: '<li>${ DisplayName }<div class="separator">|</div></li>',
                   selectable: 'single',
                   change: function () {
                       //alert( "CHANGE" );
                   },
                   dataBound: function () {
                       //alert( "dataBound" );
                   }
               } );
    If i use after the initialisation of the ListView the follwoing Code it will work but i need a way to add these items withoud rebinding the DataSource.

    var myDS = $( '#objectList' ).data( "kendoListView" ).dataSource;
    ids.push( 50 );
    ids.push( 45 );
    myDS .read();

    Your help would be very welcome!
  2. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2594 posts

    Posted 16 Jan 2013 Link to this post

    Hi Norman,

    Generally speaking, you should use the DataSource add() / insert() methods to add new items and the create transport to synchronize changes. Hence the ListView will automatically refresh.


    Regards,
    Iliana Nikolova
    the Telerik team
    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
Back to Top