You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kendo Grid点击第六列复选框设dirty为true时遇未定义错误求助

Fixing "Uncaught ReferenceError: grid is not defined" in Kendo Grid

Hey there! Let's get that Kendo Grid issue sorted out for you. The error you're seeing happens because your code is trying to use a grid variable that hasn't been properly initialized to reference your actual Kendo Grid instance. Here's how to fix it:

Step 1: Get the correct Grid instance

First, you need to grab the active Kendo Grid object. If you initialized your Grid with an ID (like $("#grid").kendoGrid(...)), you can fetch the instance using data("kendoGrid"):

let grid = $("#grid").data("kendoGrid");

Step 2: Reliably get the row containing the checkbox

Instead of relying on grid.select() (which only works if the row is explicitly selected), you can traverse up from the clicked checkbox to find its parent row. This is far more reliable for checkbox interactions:

let row = $(this).closest("tr");

Step 3: Updated working code

Putting it all together, here's your revised code. Also, note that using a class instead of an ID for your checkbox is better (since IDs must be unique in the DOM, and your Grid will render one checkbox per row):

First, update your column template to use a class instead of an ID:

<input type="checkbox" class="sixthColumnCheck" />

Then update your event handler:

$(document).on('change', '.sixthColumnCheck', function() {
  // Fetch the Grid instance
  let grid = $("#grid").data("kendoGrid");
  // Get the row associated with the clicked checkbox
  let row = $(this).closest("tr");
  // Get the data item for that row
  let gridrow = grid.dataItem(row);
  // Mark the row as dirty
  gridrow.dirty = true;
})

Why this works:

  • We're properly retrieving the Kendo Grid instance, so the grid variable is no longer undefined.
  • Using closest("tr") ensures we always get the right row, even if the user didn't select the row before clicking the checkbox.
  • Switching to a class for the checkbox avoids duplicate ID issues in the DOM, which can cause unexpected behavior down the line.

内容的提问来源于stack exchange,提问作者user9638369

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:35:05