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

ListView add new item(s)

1 Answer 1063 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Norman
Top achievements
Rank 1
Norman asked on 14 Jan 2013, 03:22 PM
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!

1 Answer, 1 is accepted

Sort by
0
Iliana Nikolova
Telerik team
answered on 16 Jan 2013, 03:26 PM
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!
Tags
ListView
Asked by
Norman
Top achievements
Rank 1
Answers by
Iliana Nikolova
Telerik team
Share this question
or