Add edit delete rows dynamically using jquery and php

Add edit delete rows dynamically using jquery and php
    In my previous similar tutorial Ajax table adding removing rows dynamically using javascript animation i demonstrated how to add and delete records dynamically to the table using jquery which became one of the famous post and got many clicks and around 6000+ downloads, that sounds excellent response.
   I received many complains from user that they are facing errors, unfortunately i wasnt able to notice the problem for long time and then i came to know that there are few issues including php PDO library. Many of the users contacted me through email and comment asking for edit record feature, While adding that feature i though to make it more beautiful using some extra css and extra js code and here is updated code Edit delete add rows dynamically using jquery and php.
    This new version is completely recoded from scratch and its customizable as well. I have added few customization option which you can customize as per your needs. You can change the input types as well, as a base i have tested this script with basic input elements like “text” and “textarea” you can add more elements like option, checkbox, dropdown etc, obviously you also have to make changes to the below javascript function code as there is code only for textbox and textarea.
As a first step you have to specify the details in javascript variables like column name, placeholder, and inputType and then specify html element type in js variable like below

var inputs = ':checked,:selected,:text,textarea,:file';

and as a second step you have to add details about the element to appear on page

createInput = function(i,str){
	str = typeof str !== 'undefined' ? str : "";
	if(inputType[i] == "text"){
		input = '';
	}else if(inputType[i] == "textarea"){
		input = '';
	}
	return input;
}

     Below are the customization options available, Read before you integrate it in your application.

Option Description Possible Values
table Table class name which will be referred all over the script, You MUST specify correct class name to make this script work.
columns Column names exactly as it is specified in mysql database column as javascript array new Array(“fname”,…,”address”);
placeholder Placeholder text for each control new Array(“Enter First Name”,…,”Enter Email”,”Enter Address”);
inputType Column names exactly as it is specified in mysql database column as javascript array new Array(“fname”,…,”address”);
savebutton
deletebutton
editbutton
updatebutton
cancelbutton
This variables hold class names which specifies which element holds what function. You dont have to make changes to js code, just change the class name and that button/element will change its behaviour.
saveImage
editImage
deleteImage
cancelImage
updateImage
This variables hold full image paths for buttons/actions.
saveAnimationDelay This option holds intereger value in miliseconds which denotes animation delay for adding new record.
deleteAnimationDelay This option holds intereger value in miliseconds which denotes animation delay for deleting new record.
effect This option specifies animation for row which will get added or deleted. 1) slide 2) flash

Download Add edit delete rows dynamically using jquery and php


Add edit delete rows dynamically using jquery (603)

About Amit

   Myself Amit Patil from Maharashtra (India). I have been working as a Web Application Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically i am a PHP developer but now a days exploring more in CSS and javascript.

Comments

  1. getRecords(); ?> $eachRecord){ ?>
    This error is found..
    i had download the script & run on my server with Database name “ajax_table” and table “info”.

    • What is the error text?

      • In each column this error occurs…
        Notice: Undefined variable: i in F:\xampp\htdocs\Add-edit-delete-rows-dynamically-using-jquery\index.php on line 92

        Notice: Undefined variable: eachRecord in F:\xampp\htdocs\Add-edit-delete-rows-dynamically-using-jquery\index.php on line 93

        Notice: Undefined variable: eachRecord in F:\xampp\htdocs\Add-edit-delete-rows-dynamically-using-jquery\index.php on line 94

        Notice: Undefined variable: eachRecord in F:\xampp\htdocs\Add-edit-delete-rows-dynamically-using-jquery\index.php on line 95

        Notice: Undefined variable: eachRecord in F:\xampp\htdocs\Add-edit-delete-rows-dynamically-using-jquery\index.php on line 96

        Notice: Undefined variable: eachRecord in F:\xampp\htdocs\Add-edit-delete-rows-dynamically-using-jquery\index.php on line 97

        • Sara, I think you havent made changes to config.php file thats why you are getting error, For the time being disable notice errors in php.ini. This is not a good practice but its a quick work around.

    • Sara, try replacing all “<?" with "<?php" – this worked for me.
      ( Problem is that you don't have this short_tag enabled in php.ini on your server)

  2. need help with forms and grids and multiple ajax tabs and login and registration system

  3. Hello Amit! Thank you great solution! Is that possible to have examples about radio with three choices, checkbox and dropdown input types. I would be very grateful about that.

  4. How would this work if my input types were select drop down lists?

  5. Hi,
    I just downloaded the code and run it, It working fine.can u please tell me how to add drop down select box to the code.
    thank you!

  6. Wonderful script. I am having a couple of small issues, mainly because I am not as proficient in javascript as i would like to be.
    In the index file, I am able to set the width and height of the edit and delete images. After I add a new record, the images for the edit and cancel are set in the script.js file. I believe the code is:
    html += ‘ ‘;

    I need to set the image width and height. Can someone tell me how to do this here.

    The 2nd issue is that I have a way to resize the entire table so that the columns stack when going from a desktop to mobile. I am using a div for this. Looks great and works except that the input area for a new record. So, what I think I need to do is add a div to this line(around line 65)
    $(“.”+table).append(blankrow);
    Can someone help me with adding the div to this line. the div in the php file is:

    Other than that, thanks for the script. works great.

    Grant

    • Sorry, looks like the code didn’t come through.
      I think where I need to add the div is line 110.
      html += “”+$(“.”+table+” tr[id="+id+"] td:first-child”).html()+””;
      Thanks,

  7. Anand Choudhary says:

    Hello Amit I need code for Add edit delete rows dynamically using jquery and php with radio buttom
    like
    Male
    Female

  8. Bhupander Kumar says:

    how to find the code above post and also add the value in database using Ajax

    Thanks

    Bhupander Kumar

    • There is social locker plugin, you click on like, share, google plus button and it will show you download button.

  9. hi, thankyou for your code. i’ve downloaded and apply to my project but there’s a problem.
    Ex= “JL TIMOR” when i try to edit the data by click inline row, it just show “JL” except we make “JL.TIMOR” it will show “JL TIMOR” . It cannot show the text after space. Do you have any sollution? Thankyou

  10. Dear Mr.Amit,

    Is that possible if i use this code for many tables? because i’ve tried it and found some troubles. For ex: i can’t edit and delete the data in a row. It will be helpfull if you give me some suggestions. Thanks.

  11. Hi Guys,
    I’ve receiving this error an I’m unable to overcome this. Considering that I’m a newbie!

    Warning: require_once(E:\wamp\www\ajax_table\config.php): failed to open stream: No such file or directory in E:\wamp\www\test\ajax_table.class.php on line 34

    #

    Time

    Memory

    Function

    Location

    1 0.0000 248528 {main}( ) ..\index.php:0
    2 0.0000 276320 require_once( ‘E:\wamp\www\test\ajax_table.class.php’ ) ..\index.php:34

    Fatal error: require_once(): Failed opening required ‘E:\wamp\www\ajax_table\config.php’ (include_path=’.;C:\wamp\php4\PEAR’) in E:\wamp\www\test\ajax_table.class.php on line 34

    #

    Time

    Memory

    Function

    Location

    1 0.0000 248528 {main}( ) ..\index.php:0
    2 0.0000 276320 require_once( ‘E:\wamp\www\test\ajax_table.class.php’ ) ..\index.php:34

    • @Nedal : I see there is discrepancy in paths “E:\wamp\www\ajax_table\config.php” and “E:\wamp\www\test\ajax_table.class.php”, There is a “test” folder in second url. Thats why its throwing error. You must have forgot to place it in right directory.

      • Hi Amit,
        I downloaded the .zip file to the wamp WWW directory, and then extracted it to a test folder.

        I’m accessing it as http://localhost/test/

        I’m not sure why its not recognizing this folder. Shall I put it on the base folder ONLY i.e. WWW

        Thank you for your prompt replies…appreciated!
        Regards,

        • I can see that in the ajax_table.class you’ve made the following:

          require_once(dirname(dirname(__FILE__)) . ‘\ajax_table\config.php’);

          there is no such folder called ajax_table in the directory that has been created by the extract. This was the problem :-)

          • Hold on, i just found out that, Users are downloading old script which throwing this error, because i just moved blog to new server then back to old and then again to the new one, and this reverted download path to old script, Probably you also have downloaded old one. Thatnks for pointing it out, I will update the code on blog and will send you a copy to your email. Cheers !!

  12. Ramesha Jogi says:

    Can you please use checkbox one column for insert, update, delete and select values. please upload that example given mail id.

Trackbacks

  1. […] Please visit and download updated code with edit functionality and many other customization options http://www.amitpatil.me/add-edit-delete-rows-dynamically-using-jquery-php […]

Speak Your Mind

*


*

Notify me of followup comments via e-mail. You can also subscribe without commenting.

More in Ajax, CSS, Misc, PHP (1 of 45 articles)


[caption id="attachment_1687" align="alignleft" width="570"] PHP Poll Script[/caption]     Are you looking for the simple and fancy PHP poll script ? ...