MiX1.TK
Site menu
Login form
Section categories
Web Development [20]
Learn about PHP & Web Development
Education [4]
Learn for Free
Knowledge & Tricks [0]
General Knowledge,computer Knowledge & tricks
Writing World [2]
A MiX World of SmS on Various Topics
Search
Main » 2012 » November » 6 » How to make a datagrid Table for Live Edit Content
9:59 PM
How to make a datagrid Table for Live Edit Content
In this demo we will make a data table showing in grid format and  using this example we can make a live table edit using Ajax and Jquery
 
how its work >> first click on any data column in showing grid . that grid will be editable ,u can change the content and after change press ENTER key to save your data into database permanently



 First of all download our Jquery Library named Cloudevils.js from our external Cloud Storage System using Following link
Download Cloudevils js pack



Extract following zip and paste the Cloudevils.js into ur project root directory


after that make a php file and paste the following code with some modifications


modify the td elements with these details


the class attribute of TD element have 3 class first is edit ( this will be static ) and second is  db_field_name ( this will be dynamic ) >> this will be the column name of database table just like email_id .

and the third class is row_id ( this will be dynamic ) >> this will be the Row Id of a database table




<html>

<head>
<script src="cloudevils.js"></script>
</head>
<body>
<table>
<tr>
 <td class="edit db_field_name row_id" >mydatataa</td>
 <td class="edit db_field_name row_id" >mydatataa</td>
 <td class="edit db_field_name row_id" >mydatataa</td>
 <td class="edit db_field_name row_id" >mydatataa</td>
</tr>
<tr>
 <td class="edit db_field_name row_id" >mydatataa</td>
 <td class="edit db_field_name row_id" >mydatataa</td>
 <td class="edit db_field_name row_id" >mydatataa</td>
 <td class="edit db_field_name row_id" >mydatataa</td>
</tr
</table>
 <script>
  $('td.edit').click(function(){

 $('.ajax').html($('.ajax input').val());
 $('.ajax').removeClass('ajax'

);

  $(this).addClass('ajax');
  $(this).html('<input id="editbox" size="'+
  $(this).text().length+'" value="' +
  $(this).text() + '" type="text">');

$('#editbox').focus();                                     
 
 } );

 $('td.edit').keydown(function(event){
     arr = $(this).attr('class').split( " " );
     if(event.which == 13)
     {
        $.ajax({    type: "POST",
                    url:'save_data.php',  //we have to make a save_data.php file to write db query
                data: "value="+$('.ajax input').val()+
                                        "&rownum="+arr[2]+"&field="+arr[1],
                success: function(data){
                     $('.ajax').html($('.ajax input').val());
                         $('.ajax').removeClass('ajax');
            }});
        }

    });

 </script>
</body>
</html>

Now the last step to run a database sql statement for updation of the data changes in Grid data


make a file named save_data.php


and paste the following code into your file

<?php
$host_name="localhost";
 $db_username="root"; // change according to your username
$db_password=""; // change accrdingly

$db_name="cloudevils"; // database name change as your db name


mysql_connect($$host_name,$db_username,$db_password);


mysql_select_db($db_name);


 $updation_table_name="users";

if($_REQUEST)

{
   $fieldname=$_REQUEST['field'];
   $id=$_REQUEST['rownum'];
   $value=$_REQUEST['value']; 

    $query="update  $updation_table_name  set $fieldname='".$value."' where id='".$id."'  ";
    mysql_query($query);
}


?>
Category: Web Development | Views: 408 | Added by: admin-priyank | Rating: 5.0/1
Total comments: 0
Name *:
Email *:
Code *:
Calendar
«  November 2012  »
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930
Entries archive
Our poll
Rate my site
Total of answers: 4
Site friends
  • Create a free website
  • Online Desktop
  • Free Online Games
  • Video Tutorials
  • All HTML Tags
  • Browser Kits
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    Creative Commons License
    Free Downloads and Services by MiX1 is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
    Copyright MyCorp © 2024