Skip to main content

Flexigrid with PostgreSQL DataBase


    Lightweight but rich data grid with re-sizable columns and a scrolling data to match the headers, plus an ability to connect to an XML or JSON data source using Ajax to load the content.
   Similar in concept with the Ext Grid only its pure jQuery love, which makes it light weight and follows the jQuery mantra of running with the least amount of configuration.



How to Use

    Adding the Flexigrid to your webpage couldn't be easier. Just download the code from http://www.flexigrid.info and copy the required files into your site's directories. You must also have a version of jQuery running on your site for this to work which can be found at jquery.com.
       You will find a flexigrid.js file in the downloaded archive. Include this file in the head section of your site as you would normally do along with the provided CSS file (you will need to copy across the entire contents of the 'css' directory including the images).
After creating a table element on your page with an id of 'flex1' for this example you can then create and include a javascript file consisting of the following code. The Flexigrid will then be created on page load.


index.html
<html>
<head>

        <link type="text/css" href="css/flexigrid.pack.css" rel="stylesheet" />
        <link type="text/css" href="css/flexigrid.css" rel="stylesheet" />
<link type="text/css" href="css/smoothness/jquery-ui-1.8.6.custom.css" rel="stylesheet" />
        <link type="text/css" href="css/demos.css" rel="stylesheet" />

<script type="text/javascript" src="js/jq.js"></script>
<script type="text/javascript" src="js/flexigrid.pack.js"></script>
        <script type="text/javascript" src="js/flexigrid.js"></script>
<script type="text/javascript">
$(function() {
        $("#flex1").flexigrid({
                url: 'page.php',
                dataType: 'json',
                colModel : [
                        {display: 'Sl', name : 'columnid', width : 40, sortable : true, align: 'left'},
                        {display: 'Name', name : 'columnvalue', width : 500, sortable : true, align: 'left'},
                ],
                buttons : [
                        {name: 'Edit', bclass: 'edit', onpress : doCommand},
                        {name: 'Delete', bclass: 'delete', onpress : doCommand},
                        {separator: true}
                ],
                searchitems : [
                        {display: 'Name', name : 'columnvalue', isdefault: true},

                ],
                sortname: "columnvalue",
                sortorder: "asc",
                usepager: true,
                title: "FlexiGrid",
                useRp: true,
                rp: 10,
                showTableToggleBtn: false,
                resizable: false,
                width: 700,
                height: 200,
                singleSelect: true
        });
function doCommand(com, grid) {
if (com == 'Edit') {
$('.trSelected', grid).each(function() {
var id = $(this).attr('id');
id = id.substring(id.lastIndexOf('row')+3);
alert("Edit row " + id);
});
} else if (com == 'Delete') {
$('.trSelected', grid).each(function() {
var id = $(this).attr('id');
id = id.substring(id.lastIndexOf('row')+3);
alert("Delete row " + id);
});
}
}
});
</script>
</head>
<body>
<table id="flex1"></table>
</body>

Page.php
<?php
// Connect to PoOstgreSQL database
$connstr = "dbname=dbname user=username password=yourpassword host=server port=1234 ";
$dbcon = @pg_connect($connstr);
pg_query("set search_path to schema");
$page = 1; // The current page
$sortname = 'columnvalue'; // Sort column
$sortorder = 'asc'; // Sort order
$qtype = ''; // Search column
$query = ''; // Search string

//Get posted data
if (isset($_POST['page'])) {
      $page = $_POST['page'];
}
if (isset($_POST['sortname'])) {
        $sortname =$_POST['sortname'];
}
if (isset($_POST['sortorder'])) {
        $sortorder = $_POST['sortorder'];
}
if (isset($_POST['qtype'])) {
        $qtype =$_POST['qtype'];
}
if (isset($_POST['query'])) {
        $query = $_POST['query'];
}
if (isset($_POST['rp'])) {
        $rp =$_POST['rp'];

}
// Setup sort and search SQL using posted data
$sortSql = "order by $sortname $sortorder";
$searchSql = ($qtype != '' && $query != '') ? "where $qtype = '$query'" : '';
// Get total count of records
$sql = "select count(*)
from \"tableName\"
$searchSql";

$stat = pg_exec($dbcon, $sql);
$data = pg_fetch_array($stat, 0);
//$data["count"];
$total = $data["count"];
// Setup paging SQL
$pageStart = ($page-1)*$rp;
$limitSql = " limit $rp OFFSET $pageStart";
// Return JSON data
$data = array();
$data['page'] = $page;
$data['total'] = $total;
$data['rows'] = array();
$sql = "select columnid,columnvalue from \"tableName\"
$searchSql
$sortSql
$limitSql";
$stat = pg_exec($dbcon, $sql);
$rows = pg_numrows($stat);  
for($i = 0; $i < $rows; $i++)
    {
    $row = pg_fetch_array($stat, $i);
$data['rows'][] = array(
'id' => $row['columnid'],
'cell' => array($row['columnid'], $row['columnvalue'])
);
}
echo json_encode($data);
?>

Ref: http://code.google.com/p/flexigrid/

Comments

Post a Comment

Popular posts from this blog

How to use PHP and GD library to convert text to an image?

To convert text to an image in PHP, you can use the GD library, which is a graphics library for creating and manipulating images. Here is an example code that creates an image with a text message: <?php // Create a blank image $image = imagecreatetruecolor( 400 , 200 ); // Set the background color $bg_color = imagecolorallocate( $image , 255 , 255 , 255 ); imagefill( $image , 0 , 0 , $bg_color ); // Set the text color $text_color = imagecolorallocate( $image , 0 , 0 , 0 ); // Write the text on the image $text = "Hello World!" ; imagettftext( $image , 24 , 0 , 50 , 100 , $text_color , 'arial.ttf' , $text ); // Output the image as PNG header( 'Content-Type: image/png' ); imagepng( $image ); // Free up memory imagedestroy( $image ); ?> This code creates a 400x200 pixels image with a white background and black text that says "Hello World!". You can change the text, font, and colors to suit your ne

Learn how to setup push notifications in your Ionic app and send a sample notification using Node.js and PHP.

Ionic is an open source mobile UI toolkit for building modern, high quality cross-platform mobile apps from a single code base. To set up push notifications in your Ionic app, you will need to perform the following steps: Create a new Firebase project or use an existing one, and then enable Firebase Cloud Messaging (FCM) for your project. Install the Firebase Cloud Messaging plugin for Ionic: npm install @ionic-native/firebase-x --save Add the plugin to your app's app.module.ts file: import { FirebaseX } from '@ionic-native/firebase-x/ngx' ; @ NgModule({ ... providers: [ ... FirebaseX ... ] ... }) Initialize Firebase in your app's app.component.ts file: import { FirebaseX } from '@ionic-native/firebase-x/ngx' ; @ Component({ ... }) export class AppComponent { constructor ( private firebase : FirebaseX ) { this .firebase.init(); } } Register your app with Firebase Cloud Messaging by adding

How can the iOS notification content be modified before it is displayed?

In iOS, you can modify the notification content before displaying it using a Notification Service Extension . A Notification Service Extension is an app extension that is used to modify the content of a remote notification before it is displayed to the user. To modify the notification content, you can follow these steps: Create a Notification Service Extension target in your Xcode project. In the extension's Info.plist file, set the NSExtensionPrincipalClass key to the name of your extension's principal class. Implement the didReceive(_:withContentHandler:) method in your extension's principal class. This method is called when a notification is received by the system. In the didReceive(_:withContentHandler:) method, modify the content of the notification as desired. You can change the notification's title, subtitle, body, sound, badge, and attachments. Call the contentHandler parameter with the modified notification content. The system will then display the modified not