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

Would like to inform user when search returns no results

1 Answer 66 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 24 Jan 2018, 11:19 AM

I'd like to give the user a popup or tooltip of some sort that lets them know that, yes a search has been conducted with the text they've provided but there are no results with their input.

Unfortunately all the events I've tried are too early (the data source's OnSelected) or don't get triggered (the search box's Search). How can I achieve this?

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 29 Jan 2018, 10:18 AM
Hello Alex,

The SearchBox does not have public client-side events that are fired when the response is received from the server. 

Nevertheless, the following JavaScript workaround can be used to check the response of the server and notify the client if there are no results: 

var $ = $telerik.$;
var oldOnCallbackResponse = Telerik.Web.UI.RadSearchBox.prototype._onCallbackResponse;
Telerik.Web.UI.RadSearchBox.prototype._onCallbackResponse = function (response, args) {
    // call the default function
    oldOnCallbackResponse.call(this, response, args);
 
    var searchbox = this;
    var split = response.split("_$$_"),
        data = $.parseJSON(split[0]);
 
    if (!data.length) {
        console.log('no records')
        // notify user or style the SearchBox
    }
}


Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
SearchBox
Asked by
Alex
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or