Coder Social home page Coder Social logo

russel2002 / editablegrid-mysql-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webismymind/editablegrid-mysql-example

0.0 2.0 0.0 1.25 MB

This example shows how to use EditableGrid with a MySQL database

License: MIT License

PHP 11.50% CSS 83.35% HTML 1.70% JavaScript 3.45%

editablegrid-mysql-example's Introduction

editablegrid-mysql-example

This example shows how to use EditableGrid with a MySQL database

Installation

First, create a database and load the script demo.sql

shell> mysql -u root -ppassword
mysql> create database demo; use demo; source demo.sql

Then copy config.php.sample to config.php and edit the values with yours.

$config = array(
"db_name" => "",
"db_user" => "",
"db_password" => "",
"db_host" => "localhost"
);   

You can load index.html in a browser and you should see the content of the table demo.

##Load data EditableGrid supports two types of data : JSON and XML. In this example, we use JSON :

$grid->renderJSON($result);  

But this works too :

$grid->renderXML($result); 

Be careful to use the appropriate function in the Javascript. JSON :

DatabaseGrid.prototype.fetchGrid = function()  {
// call a PHP script to get the data
	this.editableGrid.loadJSON("loaddata.php?db_tablename=demo");
};

XML :

DatabaseGrid.prototype.fetchGrid = function()  {
// call a PHP script to get the data
this.editableGrid.loadXML("loaddata.php?db_tablename=demo");
};

Filter

Client side

It's very easy to filter the content of the table. You can use

EditableGrid.prototype.filter = function(filterString, cols)

In this example, the filter operates on all columns

datagrid.editableGrid.filter( $(this).val());

but you can filter only on some columns. Below, the filter operates on columns 0, 3 and 5.

datagrid.editableGrid.filter( $(this).val(), [0,3,5]);

Server side

Coming...

Pagination

Client sid

Step to add a paginator

  • Add a div to render the paginator

    <!-- Paginator control -->
    <div id="paginator"></div>
    
  • In the constructor, define the pageSize and call the method that renders the paginator, once the table is rendererd.

    // define the number of row visible by page
     	pageSize: 10,
     // Once the table is displayed, we update the paginator state
       tableRendered:  function() {  updatePaginator(this); },
    
  • The method updatePaginator builds and renders the paginator.

Server side

Coming...

CRUD Actions

A column action (type HTML) has been added. With a renderer, the content is redefined to add icons or any components to manage actions on the row

Delete

The delete fonction calls delete.php with the tablename and the row id. The script executes the query that deletes the row and returns a status. If it's ok, we remove the row from the javascript model :

if (response == "ok" )
	        self.editableGrid.removeRow(id);

Add

By clicking on the add button, a form is shown to enter a name and a firstname. Data are sent to add.php that executes the insert query and returns the status of the operation.

Responsive

This example uses the first technique describes here http://elvery.net/demo/responsive-tables/. This technique is very simple, it hide less important columns on smaller screen sizes.

editablegrid-mysql-example's People

Contributors

greg31 avatar jybeaujean avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.