Today, We want to share with you jquery datatable inline edit example.In this post we will show you jquery datatable inline edit example mvc, hear for InLine Editing Using DataTable we will give you demo and example for implement.In this post, we will learn about JQuery AJAX Inline CRUD Using Laravel MySQL with an example.
Make Editable Datatable using jQuery Tabledit Plugin with PHP Ajax?
step 1: Database
-- -- Database: `testing` -- -- -------------------------------------------------------- -- -- Table structure for table `tbl_sample` -- CREATE TABLE `tbl_sample` ( `id` int(11) NOT NULL, `first_name` varchar(250) NOT NULL, `last_name` varchar(250) NOT NULL, `gender` enum('Male','Female') NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `tbl_sample` -- INSERT INTO `tbl_sample` (`id`, `first_name`, `last_name`, `gender`) VALUES (1, 'John', 'Smith', 'Male'), (2, 'Peter', 'Parker', 'Male'), (4, 'Donna', 'Huber', 'Male'), (5, 'Anastasia', 'Peterson', 'Male'), (6, 'Ollen', 'Donald', 'Male'), (10, 'Joseph', 'Stein', 'Male'), (11, 'Wilson', 'Fischer', 'Male'), (12, 'Lillie', 'Kirst', 'Female'), (13, 'James', 'Whitchurch', 'Male'), (14, 'Timothy', 'Brewer', 'Male'), (16, 'Sally', 'Martin', 'Male'), (17, 'Allison', 'Pinkston', 'Male'), (18, 'Karen', 'Davis', 'Male'), (19, 'Jaclyn', 'Rocco', 'Male'), (20, 'Pamela', 'Boyter', 'Male'), (21, 'Anthony', 'Alaniz', 'Male'), (22, 'Myrtle', 'Stiltner', 'Male'), (23, 'Gary', 'Hernandez', 'Male'), (24, 'Fred', 'Jeffery', 'Male'), (25, 'Ronald', 'Stjohn', 'Male'), (26, 'Stephen', 'Mohamed', 'Male'), (28, 'Michael', 'Dyer', 'Male'), (29, 'Betty', 'Beam', 'Male'), (30, 'Anna', 'Peterson', 'Female'), (31, 'Peter', 'Stodola', 'Male'), (32, 'Ralph', 'Jones', 'Male'); -- -- Indexes for dumped tables -- -- -- Indexes for table `tbl_sample` -- ALTER TABLE `tbl_sample` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `tbl_sample` -- ALTER TABLE `tbl_sample` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36;
Step 2: database_connection.php
Step 3: index.php
How to use Tabledit plugin with jQuery Datatable in PHP Ajax - www.pakainfo.com How to use Tabledit plugin with jQuery Datatable in PHP Ajax
Sample Data
ID First Name Last Name Gender
Step 4: fetch.php
prepare($query); $statement->execute(); $number_filter_row = $statement->rowCount(); $statement = $connect->prepare($query . $query1); $statement->execute(); $output = $statement->fetchAll(); $data = array(); foreach($output as $row) { $sub_array = array(); $sub_array[] = $row['id']; $sub_array[] = $row['first_name']; $sub_array[] = $row['last_name']; $sub_array[] = $row['gender']; $data[] = $sub_array; } function count_all_data($connect) { $query = "SELECT * FROM tbl_sample"; $statement = $connect->prepare($query); $statement->execute(); return $statement->rowCount(); } $output = array( 'draw' => intval($_POST['draw']), 'recordsTotal' => count_all_data($connect), 'recordsFiltered' => $number_filter_row, 'data' => $data ); echo json_encode($output); ?>
Step 5: action.php
$_POST['first_name'], ':last_name' => $_POST['last_name'], ':gender' => $_POST['gender'], ':id' => $_POST['id'] ); $query = " UPDATE tbl_sample SET first_name = :first_name, last_name = :last_name, gender = :gender WHERE id = :id "; $statement = $connect->prepare($query); $statement->execute($data); echo json_encode($_POST); } if($_POST['action'] == 'delete') { $query = " DELETE FROM tbl_sample WHERE id = '".$_POST["id"]."' "; $statement = $connect->prepare($query); $statement->execute(); echo json_encode($_POST); } ?>
I hope you get an idea about datatable inline editing.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.