The Grid control for JavaScript in PHP can be used to perform the following operations:
· Data binding by using PHP Web Service
· CRUD Operations
The following code example illustrates how DataManager properties are used to perform CRUD operations in Remote Web services, and also configure data by using the UrlAdaptor.
var data = ej.DataManager( { url: 'http://localhost/phpservice/server.php/?action=get_Data', insertUrl: 'http://localhost/phpservice/server.php/?action=insert_Data', updateUrl: 'http://localhost/phpservice/server.php/?action=update_Data', removeUrl: 'http://localhost/phpservice/server.php/?action=delrec' }); data.adaptor = new ej.UrlAdaptor();
To bind data to the Grid control, you can use the PHP get_Data Web service method. This method gets the JSON data to be loaded into the grid. The following code example illustrates this.
url: ’http://localhost/phpservice/server.php/?action=get_Data’
With the insertUrl property, you can invoke the insert_Data Web service method to add new data to the grid. The “/?action=insert_Data” section in the URL invokes the Web service method to get the JSON object that contains the data to be inserted to perform the insertion operation. The following code example illustrates this.
insertUrl: ’http://localhost/phpservice/server.php/?action=insert_Data’ $json_insert = file_get_contents('php://input'); $obj_insert = json_decode($json_insert,true)
With the updateUrl property, you can invoke the update_Data Web service method to update grid data. This method posts the JSON object that contains the updated information to the database. The following code example illustrates this.
updateUrl: ’http://localhost/phpservice/server.php/?action=update_Data’
With the removeUrl property, you can invoke the delrec Web service method to delete grid data. In the server, the “key” to delete the record is fetched from the posted JSON object, and the record is deleted from the database by using the Web service method. The following code example illustrates this.
removeUrl: ’http://localhost/phpservice/server.php/?action=delrec’
To learn more about this, you can download a free sample here:
Content Contributors: Bharath M; Madhu Sudhanan Content Editor: GeeGee Inekeya