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

How to read 2nd grid based on the 1st grid

8 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
york
Top achievements
Rank 1
york asked on 06 Nov 2015, 06:38 AM

Hi,

I have 2 Kendo Grids in which 2nd grid is read based on the selection of row of 1st grid. The code is:

1st grid

        <% Html.Kendo().Grid<EvaluationsQuestionsEvaluationVersionGridViewModel>(Model.VersionsGridModel)
            .Name("Versions")
           .DataSource(dataSource => dataSource
                    .Ajax()
                    .Model(model => model.Id(a => a.EvaluationVersionId))
                    .ServerOperation(true)
                    .Create(create => create.Action("InsertEvaluationVersion", "Evaluations"))
                    .Read(read => read.Action("LoadEvaluationsQuestionsEvaluationVersionGridAjax", "Evaluations"))
                    .Update(update => update.Action("UpdateEvaluationVersion", "Evaluations").Data("onUpdateEvaluationVersion"))
                )
            .Events(e => e.Change("onVersionGridRowSelect")
                          .Edit("onEditEvaluationsVersion")
                          .Save("onSaveEvaluationsVersion")
                    )​

.....

2nd grid

        <% Html.Kendo().Grid<EvaluationsQuestionsEvaluationPillarsGridViewModel>()
            .Name("Pillars")
            .DataSource(dataSource => dataSource
                  .Ajax()
                  .Model(model => model.Id(a => a.EvaluationMasterPillarId))
                  .ServerOperation(true)
                  .Read(read => read.Action("LoadEvaluationsQuestionsEvaluationPillarsGridAjax", "Evaluations")
                                    .Data("onLoadEvaluationsQuestionsEvaluationPillarsGridData"))
             )​

......

        function onVersionGridRowSelect(e) {
            var grid = $("#Versions").data("kendoGrid");
            var currentRow = grid.dataItem(grid.select());
            var evaluationVersionId = currentRow.EvaluationVersionId;

            $('#evaluationVersionId').val(evaluationVersionId);
            $("#Pillars").data("kendoDropDownList").dataSource.read();
        }

        function onLoadEvaluationsQuestionsEvaluationPillarsGridData(e) {
            var evaluationVersionId = $('#evaluationVersionId').val();  // "evaluationVersionId" is set beforehand
            var showDeletedCheckbox = $('#Checkbox1').val();

            return { evaluationVersionId: evaluationVersionId, showDeleted: showDeletedCheckbox }
        }

But 2nd grid can not be read because Data function "onLoadEvaluationsQuestionsEvaluationPillarsGridData" is not called. So what is the problem in code?​ Thanks.

8 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 06 Nov 2015, 08:08 AM

Hello york,

What exactly is the issue that you are experiencing with the function providing the additional read data? Please elaborate further.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
york
Top achievements
Rank 1
answered on 12 Nov 2015, 12:30 AM

Hi Dimiter,

I attach a ​sample project ​named MVC_Controls_Kendo as well as MVC_Controls_Kendo Database to show you the problem. Because of the size limit, I remove the package in the
project. The package include, Kendo MVC (2015.1.429.440.Trial), MVC 4
and many others. The simplest way to recreate the solution is to create
new Telerik MVC project (name: MVC_Controls_Kendo) and select .Net 4 and
ASPX (not razor), and add the source files attached.

 Please add the OTPTEST.mdf in attached MVC_Controls_Kendo Database to the Data folder for SQL Server Express on the your pc and attach it in SQL management studio. Then modify the connection string in Webconfig in MVC_Controls_Kendo project and App.Config file in Data project. Currently it is:
    <add name="OTPTESTEntities" connectionString="metadata=res://*/Model3.csdl|res://*/Model3.ssdl|res://*/Model3.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ZHANG-PC\SQLEXPRESS;initial catalog=OTPTEST;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Replace ZHANG-PC with your pc name. After launching the project, just click on "Evaluation Questions", which
will go to EvaluationQuestions.aspx.

After selecting a row in 1st grid (Name("Versions")), I want to pass EvaluationVersionId and value of a checkbox (name='showDeletedQuestions') to read function (LoadEvaluationsQuestionsEvaluationPillarsGridAjax) of 2nd grid (Name("Pillars")) and reload the "Pillars" again.  This is done in event onVersionGridRowSelect in "Versions". But after several tries, I failed to send above 2 parameters (the code is in  onVersionGridRowSelect). Please help me to find way to pass EvaluationVersionId and value of a checkbox to LoadEvaluationsQuestionsEvaluationPillarsGridAjax in onVersionGridRowSelect. Thanks. 

0
york
Top achievements
Rank 1
answered on 12 Nov 2015, 12:31 AM
Oops, I forget to attach 2 files. Here they are.
0
Dimiter Madjarov
Telerik team
answered on 13 Nov 2015, 09:34 AM

Hello york,

The read method of the dataSource accepts a data object that could be used to pass additional parameter to the read action. I assume that you could utilize it in the current case too.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
york
Top achievements
Rank 1
answered on 13 Nov 2015, 09:21 PM

Hi Dimiter,

I use read Data method named "onLoadEvaluationsQuestionsEvaluationPillarsGridData". You can find it (comment out) in the project in grid "Pillars". The code is:

        function onLoadEvaluationsQuestionsEvaluationPillarsGridData(e) {
            var evaluationVersionId = $('#evaluationVersionId').val();
            var showDeletedCheckbox = $('#Checkbox1').val();

            return { evaluationVersionId: evaluationVersionId, showDeleted: showDeletedCheckbox }
        }

But the grid "Pillars" can not be read. Can you find out why? Thanks.

 

0
Dimiter Madjarov
Telerik team
answered on 16 Nov 2015, 08:30 AM

Hello york,

This Data() method is not added in the Pillars Grid dataSource configuration options. You should include it if this is the way the additional data should be send.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
york
Top achievements
Rank 1
answered on 16 Nov 2015, 09:05 PM

Hi Dimiter,

I commented it out because it was not working. You can uncomment it and run it. But the grid "Pillars" can not be read. Can you find out why? Thanks.

0
york
Top achievements
Rank 1
answered on 16 Nov 2015, 11:25 PM

Hi Dimiter,

This is solved. The reason is not due to Data method in Read.Action, but "$('#Checkbox1').val()" is not correct.

Tags
Grid
Asked by
york
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
york
Top achievements
Rank 1
Share this question
or