Kendo Grid列Tooltip返回'e.uniqueSort is not a function'错误求助
I’ve run into this exact error before when working with Kendo Tooltips and numeric data—it almost always boils down to a mismatch between what the tooltip expects (string content) and what you’re returning (a number), plus potential timing issues with initialization. Let’s walk through the fixes step by step.
Core Cause
Your AmountFarei field is defined as a number type, and when you return it directly in the tooltip’s content function, Kendo’s internal logic tries to run string-specific methods (like uniqueSort) on it, which throws the error because numbers don’t have those methods.
Step-by-Step Fixes
1. Convert Numeric Content to a String
Wrap your numeric value in a string conversion to ensure the tooltip gets the content type it expects:
return dataItem.AmountFarei.toString(); // Or format it if needed, e.g.: return `Amount: ${dataItem.AmountFarei}`;
2. Initialize Tooltip After Grid is Fully Ready
Don’t initialize the tooltip outside the grid’s initialization flow—use the grid’s dataBound event to ensure the grid’s DOM is fully rendered and data is loaded before attaching the tooltip. This avoids issues where the tooltip tries to target elements that don’t exist yet.
3. Reuse the Existing Grid Instance
Instead of re-querying $("#grid") in the tooltip function, use the already-defined gridMain variable to avoid redundant DOM lookups and potential context mismatches.
Modified Full Code
Here’s how your updated code should look with all fixes applied:
function fillGrid(dataSource) { var gridMain = $("#grid").kendoGrid({ scrollable: true, filterable: { mode: "row" }, height: 450, dataSource: { data: dataSource, schema: { model: { id: "ID", fields: { ID: { type: "number" }, Product: { type: "string" }, AmountFarei: { type: "number" } } } }, pageSize: 15 }, columns: [ { field: "Product", title: "Product Code", width: "11%", attributes: { "class": "meghdarVahedFari" } } ], dataBound: function() { // Attach tooltip only after grid data is bound and DOM is ready gridMain.table.kendoTooltip({ filter: ".meghdarVahedFari", position: "right", showOn: "click", autoHide: false, width: 200, content: function (e) { var row = $(e.target).closest("tr"); var dataItem = gridMain.dataItem(row); // Convert number to string to fix the uniqueSort error return dataItem.AmountFarei.toString(); } }).data("kendoTooltip"); } }).data("kendoGrid"); }
Additional Check
If the error persists, verify you’re using a stable, up-to-date version of Kendo UI—older versions had edge cases with content type handling that were fixed in later releases.
内容的提问来源于stack exchange,提问作者Farshad.Ranaei

