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

Best way to handle no data in a DataSource

3 Answers 546 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
PromptAlert Inc.
Top achievements
Rank 1
PromptAlert Inc. asked on 05 Jul 2012, 04:44 AM
We are using a DataSource for a search result. When there are rows returned, we display a template in a ListView. When there is no data returned from the search we'd like to indicate 'No records to display' similar to the RadGrid setting.

What is the best way to do this? We can return 'No records to display' in the json response but it will not fit well into our template.

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 05 Jul 2012, 09:02 AM
Hello,

Even if there are no returned records, the dataBound event will be fired. You can use the corresponding handler to modify the ListView's markup and inject an appropriate message.

if (this.dataSource.total() == 0) {
       // no records
}


Greetings,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
PromptAlert Inc.
Top achievements
Rank 1
answered on 06 Jul 2012, 08:07 AM
Thanks. The problem with this solution is that we are using a template to display the results.

Something like:
template: "Name: ${data.name}<br/>Result: ${data.result}

So we'd get something like:

Name: No records to display
Result:

We'd prefer:

No records to display 


0
Robert
Top achievements
Rank 1
answered on 09 Jul 2012, 07:12 AM
I had a similar problem, I have just used jquery to insert what I want in the event that no results have been returned.

For example

$("#auditResults").kendoListView({
template: "<li id='structuredata-${id}' title='${notes}'>${title} - ${lastupdated}</li>",
                dataSource: auditDataSource,
selectable: true,
dataBound: function () {
if (this.dataSource.total() == 0) 
{
// no records
$("#auditResults").html('<li>Nothing Found.</li>');
}
}
});

You can just change the selector to whatever you need and push in the html as you need to.
Tags
Data Source
Asked by
PromptAlert Inc.
Top achievements
Rank 1
Answers by
Dimo
Telerik team
PromptAlert Inc.
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or