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

No records display message

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 17 Jul 2012, 09:22 AM

Hi,

If a grid has no records I do not want to display the grid at all (including the headers) but would like to display a text message instead. Is this possible using Kendo?

Thanks

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 17 Jul 2012, 04:17 PM
Hello Simon,

To achieve this I recommend hooking up to the change event of the dataSource and creating the grid only if there are records. For example:
var dataSource = new kendo.data.DataSource({
    //....
    change: function() {
        if ( this.data().length ) {
            createGrid();
        } else {
            //display message
        }
    }
});
 
function createGrid() {
    $("#grid").kendoGrid({
        dataSource: dataSource,
        //...
    });
}

When you use this approach please consider the following cases:
  • the event throws after each change in the dataSource records, not only after the data is fetched from the server, so you have to assure that the grid will be initialized only once
  • the dataSource have to be read manually as there is no widget bound to it - dataSource.read();

I hope this helps.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or