Note that there are some explanatory texts on larger screens.

plurals
  1. POadd new row to empty kendo grid
    primarykey
    data
    text
    <p>I have this grid</p> <pre><code>$("#email-grid").kendoGrid({ dataSource: { transport: { read: { url: "operations/get_emails_sales_reps.php?salesRepsId=" + salesRepsId, type: "GET" }, update: { url: "operations/edit_email.php?salesRepsId=" + salesRepsId, type: "POST", complete: function (e) { $("#email-grid").data("kendoGrid").dataSource.read(); } }, destroy: { url: "operations/delete_email.php", type: "POST", complete: function (e) { $("#email-grid").data("kendoGrid").dataSource.read(); } }, create: { url: "operations/add_email.php?salesRepsId=" + salesRepsId, type: "POST", complete: function (e) { $("#email-grid").data("kendoGrid").dataSource.read(); } }, }, schema: { data: "data", total: "data.length", //total amount of records model: { id: "SalesRepId", fields: { EmailType: { defaultValue: { EmailTypeId: 2, EmailTypeName: "Home" } }, EmailText: { type: "string" }, IsMainEmail: { type: "boolean" } } } }, pageSize: 5, }, height: 250, filterable: true, sortable: true, pageable: true, reorderable: false, groupable: false, batch: true, navigatable: true, toolbar: ["create", "save", "cancel"], editable: true, columns: [{ field: "EmailType", title: "Type", editor: EmailTypeDropDownEditor, template: "#=EmailType.EmailTypeName#" }, { field: "EmailText", title: "Email", }, { field: "IsMainEmail", title: "Main?", width: 65, template: function (e) { if (e.IsMainEmail == true) { return '&lt;img align="center" src ="images/check-icon.png" /&gt;'; } else { return ''; } } // hidden: true }, { command: "destroy", title: "&amp;nbsp;", width: 90 }, ] }); </code></pre> <p>the code in the server side (get_emails_sales_reps.php) </p> <pre><code>&lt;?php require_once ("../lib/salesrep.php"); require_once ("../lib/helper.php"); // add the header line to specify that the content type is JSON header("Content-type: application/json"); $options = array(); $result = SalesRep::getRepEmails($_GET["salesRepsId"]); if (isset($result) &amp;&amp; $result != null) { $result = _object_to_array($result); if (isset($result[0]) &amp;&amp; is_array($result)) { for ($i = 0; $i &lt; count($result); $i++) { $result[$i]["EmailType"] = array("EmailTypeName" =&gt; $result[$i]["EmailType"], "EmailTypeId" =&gt; $result[$i]["EmailTypeId"]); } } else { $result["EmailType"] = array("EmailTypeName" =&gt; $result["EmailType"], "EmailTypeId" =&gt; $result["EmailTypeId"]); } if (isset($result) || $result != null) { echo "{\"data\":" . json_encode($result) . "}"; } else { echo "{\"data\": {} }"; } } ?&gt; </code></pre> <p>when the grid has one record or more, I can add new record without any errors, but when there are no records the grid and try to add a new record. I get this error</p> <blockquote> <p>Uncaught TypeError: Cannot read property 'length' of undefined</p> </blockquote> <p>please, how can I fix this ??</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload