To perform operations on the data in the data table, the first step is to obtain the data in the data table. Article The method for creating a store in is also slightly adjusted to allow it to read data from the data table.
CopyCode The Code is 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 to the SQL database, obtaining data and converting it to the JSON format to prepare for ext reading.Copy codeThe Code is 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 );
Another point to modify is to add and modify the onsubmitclick method of the form.
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 must pass a series of parameters:
URL: the URL address for data processing. Here, a URL is passed in to process new operations.
Success: If the submitted data processing is successful, the processing code specified by this parameter is called back.
Waittitle: the title of the dialog box that appears when data is submitted
Waitmsg: Information in the pop-up dialog box when data is submitted
Scope: the object referred to by this in the callback function
it must be noted that a JSON string must be returned in the PHP file for data processing. If the string contains "success: True", the string is processed into or. Otherwise, the processing fails. For example, the following code copy Code is as follows: require ('json. PHP ');
require ('uai _ personal_info.php');
$ Rs =$ _ post;
$ Rs ["success"] = true; // indicates that the processing is successful
$ 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);
deletion is slightly different from addition and modification. Because deletion does not require a pop-up form to operate data, we use Ext. the copy Code code of the Ajax object is 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
},