New to Kendo UI for jQuery? Start a free 30-day trial

Processes and applies AI-generated commands to the Grid. Use this method when implementing custom AI service integrations or when working with backend AI implementations.

The method automatically executes Grid operations based on commands returned from AI services. The Grid's built-in AI Assistant uses this method internally, and you can use it directly when implementing custom AI integrations.

Parameters:responseObject

The AI service response object containing commands to execute.

response.commandsArray

An optional message to display in the AI Assistant output view when using the built-in AI Assistant.

<div id="grid"></div>
<script>
  $("#grid").kendoGrid({
    columns: [
      { field: "name" },
      { field: "age" },
      { field: "city" }
    ],
    dataSource: [
      { name: "Jane Doe", age: 30, city: "New York" },
      { name: "John Doe", age: 33, city: "London" },
      { name: "Sam Smith", age: 25, city: "Paris" },
      { name: "Emily White", age: 28, city: "Berlin" }
    ],
    sortable: true,
    filterable: true,
    toolbar: [{
      template: '<input id="aiPrompt" class="k-input" placeholder="Ask AI to manipulate the grid..." style="width: 300px; margin-right: 10px;" />' +
                '<button id="askAI" class="k-button k-button-primary">Apply</button>'
    }]
  });

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

  $("#askAI").on("click", function() {
    var prompt = $("#aiPrompt").val();

    if (!prompt) {
      return;
    }

    $.ajax({
      url: "https://demos.telerik.com/service/v2/ai/grid/smart-state",
      method: "POST",
      contentType: "application/json",
      data: JSON.stringify({
        "role": "user",
        "contents": [{
            "$type": "text",
            "text": prompt
        }],
        "columns": grid.columns.map((col, idx) => {
            let colType;

            if (col.selectable) {
                colType = "checkbox";
            } else if (col.command) {
                colType = "command";
            } else if (col.draggable) {
                colType = "draggable";
            }

            const colConfig = { ...col, "id": `${col.uid}` };

            if (colType) {
              colConfig.type = colType;
            }

            return colConfig;
          })
      }),
      success: function(response) {
        grid.handleAIResponse(response);
        $("#aiPrompt").val("");
      },
      error: function(xhr) {
        alert("AI service error: " + xhr.responseText);
      }
    });
  });
</script>
Not finding the help you need?
Contact Support