How to create a CRUD using Kendo UI grid popup editing and Codeigniter (Controller,Model,View)? - El Forum - 08-15-2013
[eluser]rochellecanale14[/eluser]
Hello guys can you give me an example of how can I access the methods/functions in Codeigniter to Kendoui datagrid?
I used the example of Kendo UI but i don't know how to integrate it with CI:
Code: [removed]
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products", /* is this the view list? Can i use <?php echo site_url('user_controller/index'); ?> ? */
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update", /* How can i get the hidden id> */
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 430,
toolbar: ["create"],
columns: [
{ field:"ProductName", title: "Product Name" },
{ field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "100px" },
{ field: "UnitsInStock", title:"Units In Stock", width: "100px" },
{ field: "Discontinued", width: "100px" },
{ command: ["edit", "destroy"], title: " ", width: "160px" }],
editable: "popup"
});
});
[removed]
</div>
VIEW PROCESS
For example if I have a controller like this(user_controller)
Code: public function index(){
$data['users'] = $this->user_model->user_detail();
$this->load->view('Supplier/index',$data);
}
And a model like this(user_model)
Code: public function user_detail(){
$getUser = "SELECT * FROM users";
$resultUser = $this->db->query($getUser);
return $resultUser;
}
How can i display i put this in datasource?
ADD PROCESS
If i have a function like this
Code: public function addNewUser(){
$this->load->view('User/addNewUser');
}
If I have a view like this
Code: /* how do i create this form in kendoUI?*/
echo form_open('user_controller/addNewUser');
echo "<input type='text' name='name' value='' required='required' />";
echo "<input type='submit' value='ADD'/>";
echo form_close();
And a model like this
Code: public function addNewUser(){
$add = array(
'id' => null,
'name' => $this->input->post('name')
);
$this->db->insert('users',$add);
}
UPDATE PROCESS
And if i have a function for update like this:
Code: public function user_update(){
$this->user_model->userUpdateInfo();
redirect('user_controller/index');
}
And in my model like this
Code: public function userUpdateInfo(){
$id = $this->input->post('id');
$name = $this->inpput->post('name');
$updateNow = array(
'name' => $name
);
$this->db->where('id',$id);
$this->db->update('users',$updateNow);
}
In delete same question in update
That's all guys I hope you can help me. I have a little understanding in jquery but I want to learn it. If you know some sites that same that can give me example of it just comment me. Or can you give me a working example of it? Email me at [email protected] or [email protected]
|