This is a migrated thread and some comments may be shown as answers.

Batch Editing Not Working

6 Answers 315 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 11 Apr 2012, 09:41 PM
Hi,

I'm trying to build a billing system using a grid to select the items that are billable in a time range. I have the following php file that feeds the grid and handles the post as in the blog tutorials. When the Save button is clicked the grid posts to the php page correctly but the update does not happen and I get the following error in firebug:

a is undefined
http://localhost/...../kendo.all.min.js
Line 8

Here's the php code:

<?php
$link = mysql_pconnect("localhost", "user", "pass") or die("Unable To Connect To Database Server");
mysql_select_db("db-name") or die("Unable To Connect To DB");

// add the header line to specify that the content type is JSON
header("Content-type: application/json");

// determine the request type
$verb = $_SERVER["REQUEST_METHOD"];

// handle a GET
if ($verb == "GET") {

$arr = array();
$rs = mysql_query("SELECT
contracts_copy.contractID AS ID,
contracts_copy.artistID,
contracts_copy.contract_number AS Contract,
contracts_copy.play_date AS Date,
contracts_copy.billable AS Billable
FROM
contracts_copy
WHERE
contracts_copy.play_date >= '2012-01-01' AND
contracts_copy.offer_status = 'Confirmed'
");
 
while($obj = mysql_fetch_object($rs)) {
    $arr[] = $obj;
}

echo "{\"data\":" .json_encode($arr). "}";
}

    // handle a POST
if ($verb == "POST") {

     // get the parameters from the post. escape them to protect against sql injection.
    $Billable = mysql_real_escape_string($_POST["Billable"]);
    $Id = mysql_real_escape_string($_POST["ID"]);
    
    $rs = mysql_query("UPDATE contracts_copy SET billable = '" .$Billable."' WHERE contractID = '" .$Id."'");
   
   if ($rs) {
        echo json_encode($rs);
    }
    else {
        header("HTTP/1.1 500 Internal Server Error");
        echo "Update failed for ID: " .$Id;
    }
}
?>

When viewing the json directly in the browser it works fine. The post from the grid looks fine too:

models[0][Billable] true
models[0][Contract] EK.03.29-30.2012.HollySprings.NC
models[0][Date] 2012-03-29
models[0][ID] 2218
models[0][artistID] 73

The Billable field is the only editable one and is passed correctly. The response from json is also correct...true. But the table is not updated with the Billable value (true) and the grid doesn't show the update.

Here's my page code:

<div id="wrap" class="k-content">
<div id="example" class="k-content">
            <div id="grid"></div>

            <script>
                $(document).ready(function () {
                  dataSource = new kendo.data.DataSource({
                                transport: {
                                        read: "../data/billable.php",
                                        update: {
                                        url: "../data/billable.php",
                                        type: "POST"
                                            }
                                        },
                                    parameterMap: function(options, operation) {
                                    if (operation !== "read" && options.models) {
                                        return {models: kendo.stringify(options.models)};
                                    }
                                },
                            
                            batch: true,
                            autoSync: true,
                             pageSize: 30,
                                schema: {
                                    data: "data",
                                model: {
                                    id: "ID",
                                    fields: {
                                        Contract: { editable: false },
                                        Date: { editable: false},
                                        Billable: {editable: true, type: "boolean" }
                                  
                                    }
                                }
                            }
                        });

                    $("#grid").kendoGrid({
                        dataSource: dataSource,
                        pageable: true,
                        height: 400,
                        toolbar: ["save", "cancel"],
                        columns: [
                            { field:"ID", title: "ID", width: "25px" },
                            { field: "Contract", title:"Contract", width: "150px" },
                            { field: "Date", title:"Date", width: "150px" },
                            { field: "Billable", width: "100px" }
                            ],
                        editable: true
                    });
                });
            </script>
        </div>


</div>

I hope someone can help. It's probably something simple I'm overlooking. It seems odd that I'd get the true response from my php/json page if the update didn't happen?

Any help is appreciated.
Tony

6 Answers, 1 is accepted

Sort by
0
Tony
Top achievements
Rank 1
answered on 12 Apr 2012, 03:18 AM
To update this, I now have this updating the record properly, however. I'm still getting the error in Firebug. Should I be worried about it? It seems to work but still throws the error on update.

Thanks again.
0
Nikolay Rusev
Telerik team
answered on 12 Apr 2012, 08:49 AM
Hello Tony,

Provided information is not sufficient to suppose what might cause the error. Can you provide us with more details on the error?

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tony
Top achievements
Rank 1
answered on 12 Apr 2012, 06:02 PM
Hi,

Thanks for the quick response!

I've attached an image of the firebug error screen showing the error I'm getting on all posts from the grid. The updates work now and aside from this error I'm ok with it. The error points to line 8 of kendoui.all.min.js, which contains the function a code:

(function(a,b){function bf(d,e){var f={},g;for(option in
e)g=be(d,option),g!==b&&(bb.test(option)&&(g=c.template(a("#"+g).html())),f[option]=g);return
 f}function be(d,e){var f;e.indexOf("data")

The error states that 'a is undefined' on line 8 above.

Again, the data is fine, the updates happen as planned and the json response is true. This seems to be a bug in the script?

Hope this helps.

Tony
0
Alexander Valchev
Telerik team
answered on 16 Apr 2012, 09:21 AM
Hello Tony,

Thank you for the detailed error information, but I am afraid that we still cannot determine why this error occurs.
Is it possible to send us a small runnable project that reproduces the issue? Such example will be much appreciated and will help us to investigate what is causing the described behaviour.

Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris Foster
Top achievements
Rank 1
answered on 03 May 2012, 06:58 AM
Do you need to include ID in the field list of your datasource schema? Most of the samples I've seen do.
0
Alexander Valchev
Telerik team
answered on 07 May 2012, 09:57 AM
Hi Chris,

The model ID field is not mandatory - on the client the dataSource creates its own unique identifier (uid) for each record. The Grid widget uses the uid field of the Model instead of the id.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Tony
Top achievements
Rank 1
Answers by
Tony
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Alexander Valchev
Telerik team
Chris Foster
Top achievements
Rank 1
Share this question
or