Grid instance in javascript

1 Answer 17 Views
Grid
Cvetka
Top achievements
Rank 1
Cvetka asked on 01 Jul 2025, 08:39 AM

Hi,

I'm using Teleik Core components, latest version in mvc application.

I have defined grid in view with name "gridMara"
In javascript i have code:

var gridMara = $("#gridMara").data("kendoGrid");

I checked in console, $("#gridMara") is initialized.
But when i use statement: 

var gridMara = $("#gridMara").data("kendoGrid");

the value of gridMara is undefined.

Please help.

Regards,
Tomaz

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 01 Jul 2025, 03:01 PM

Hello Tomaz,

 

Thank you for reaching out.

You can access the Grid after its data has been loaded:

<script>
    function buttonClick(){
      var gridMara = $("#gridMara").data("kendoGrid");
      alert("Access from manual action: "+gridMara.element[0].id);
    }
    function dataBound(e){
      var gridMara = e.sender;
      alert("Access from initial load: "+gridMara.element[0].id);
    }
</script>
I have prepared a live sample for your convenience:
https://netcorerepl.telerik.com/GJOVabvJ01JxmxuU24

Can you please check it and let me know if you find it helpful?

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Cvetka
Top achievements
Rank 1
commented on 01 Jul 2025, 04:05 PM

Thx for your example.

I didn't have this problem before, it appears when I load kendo scripts with options type="module" in _layout.cshtml.


 <script type="module" src="~/js/kendo.all.min.js"></script>
 <script type="module" src="~/js/kendo.aspnetmvc.min.js"></script>
 <script type="module" src="~/js/kendo.culture.sl-SI.min.js"></script>
 <script type="module" src="~/js/kendo.timezones.min.js"></script>
If I load this scripts without type="module" everything works fine.

Grid is defined in mara.cshtml. In same file i have:


<script>
    $(document).ready(function ($) {
	 
        gridMara = $("#gridMara").data("kendoGrid");
        dataSource = gridMara.dataSource;
	 
    });
</script>

So this worked before i load kendo scripts with type="module".

So I don't understand what has changed?

Regards,
Tomaz


Eyup
Telerik team
commented on 04 Jul 2025, 03:16 PM

Hi Tomaz,

In the other ticket I have demonstrated how you can implement pdf.js without changing all the project scripts to type=module.

Please use this solution instead and verify that everything works as before.

Cvetka
Top achievements
Rank 1
commented on 07 Jul 2025, 05:44 AM

Thx, the problem has been resolved.

Best regards,
Tomaz
Tags
Grid
Asked by
Cvetka
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or