To implement the data in a datasheet, the first step is to get the data from the data table, and we'll tweak the method of creating the store in the previous article to read the data from the datasheet.
Copy Code code as follows:
This.departmentstore = new Ext.data.JsonStore ({
Proxy:new Ext.data.HttpProxy ({url: "http://localhost:8080/Test_EXT/DB/Department.php"}),
Fields: ["Department_code", "Department_name", "manager", "Division_code"]
});
Department.php, is responsible for connecting the SQL database, taking the data and converting it to JSON format, to prepare for the ext read.
Copy Code code as follows:
<?php
Require (' json.php ');
Require (' uai_personal_info.php ');
$p = new Uai_personal_info ();
$result = $p->getdepartmentlist ();
$json = new Services_json ();
echo $json->encode ($result);
One more thing to change is the Onsubmitclick method for adding and modifying forms
Onsubmitclick:function () {
if (This.url!= "") {
This.form.submit ({url:this.url, success:this.onSubmit,
Waittitle: "Save Data", waitmsg: "transcation process ...", scope:this});
This.fireevent ("Submit", this, this.form.getValues ());
}
},
The Submit method needs to pass a series of parameters:
URL: The URL address for data processing, where a URL to handle the new action is passed in
Success: If the submission of data processing succeeds, the processing code specified by this parameter is recalled
Waittitle: Title of pop-up dialog box when data is submitted
Waitmsg: Information content of pop-up dialog box when data is submitted
Scope: This in the callback function refers to the object
The point to note here is that in the PHP file that processes the data, a JSON string must be returned, and if "Success:true" is included, the processing is or is not considered to be a failure. For example, the following code
Copy Code code as follows:
<?php
Require (' json.php ');
Require (' uai_personal_info.php ');
$rs = $_post;
$rs ["Success"] = true; Indicates successful processing
$sql = "INSERT into Uai_department (Department_code, Department_name, manager, Division_code) VALUES ('").
$_post["Department_code"]. "', '" . $_post["Department_name"]. "', '" . $_post["Manager". "', '" . $_post["Division_code"]. "')";
$p = new Uai_personal_info ();
$rs ["r"] = $p->insert_department ($sql);
$json = new Services_json ();
echo $json->encode ($RS);
The removal process is slightly different from the new and modified, because the deletion does not require the pop-up form to operate on the data, so we use the Ext.ajax object instead
Copy Code code as follows:
Remove:function () {
var r = This.getactiverecord ();
Ext.Ajax.request ({url: "http://localhost:8080/Test_EXT/DB/delete_dept.php", params: {Department_code:r.get (" Department_code ")});
This.getstore (). Remove (R);//delete client data
},