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

Grid holds previous datasource

2 Answers 207 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Claudia
Top achievements
Rank 1
Claudia asked on 14 May 2019, 03:39 PM

Hi

I'm using a grid to show  the results form a search and also "hierarchy" for details of each result. Every time I search the new values shows perfectly fine but the detailInit event is not working is I need. First time the details looks good but if I search again the details grid does not show and I noted that it is using data from previous search results. I assumed that the fact that it is not showing the details is because of that but not sure. 

I have something like this:

function search()
{   
    getDataSource();
    createGrid();
}
 
function createGrid()
 
{
 
$("#grid").kendoGrid({
 
...
 
detailInit: detailInit,
 
....
 
});
 
}
 
function detailInit(e)
 
{
 
var trackId = e.data.TrackingID;// parent row value the one that is holding previous result
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource:{
 transport: {
 read:
 {
 url: "API_URL",
 dataType: "json",
 type: "POST"
 },
parameterMap: function (data, type) {
var result = {
trackingId: trackId,
 }
 return kendo.stringify(result);
 }
 },
 },
 scrollable: false,
 sortable: true,
 pageable: false,
 columns: [......]
 });
 
}

 

Thank you

2 Answers, 1 is accepted

Sort by
0
Claudia
Top achievements
Rank 1
answered on 14 May 2019, 03:58 PM

So I was initializing the grid every time I search, now I change it like this and is working. But any way if there is something I need to do different to make it work better I will appreciate the advise.

function search()
{
     
    if ($("#grid").data("kendoGrid"))
        $("#grid").data("kendoGrid").dataSource.read();
    else {
        getDataSource();
        createGrid();
    }
}
0
Tsvetomir
Telerik team
answered on 16 May 2019, 07:28 AM
Hi Claudia,

Thank you for the provided code snippets and clarifications on the scenario on hand.

Generally, the approach that you have undertaken as an option is a suitable fit. This is due to the fact that in case the grid has been already initialized, the data source would not be interchanged with the result from the search. That is why, you would have to either make a Read request manually to load the new records or completely interchange the data source. 

The change of the data sources could be done via the setDataSource() method which is called upon the instance of the Kendo UI Grid widget. Nevertheless, the approach that you have undertaken looks correct to me and if it is working as expected, there is no need to change it.

Let me know in case any queries arise.


Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Claudia
Top achievements
Rank 1
Answers by
Claudia
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or