Tutorial Extjs: Grouping

I hope this day is a nice day for you and your family, ang  i hope you still hold to the spirit of learning. Now let’s continue this tutorial, in this section we will about how to make Grouping in Extjs. Grouping is very useful for us in the search data, with the grouping we will be more easily explore the data that we find.

Create a grouping of extjs is not too difficult, we just add a little script from the previous tutorial.
Files that we need to create this tutorial are as follows:

1.  Create table in database

CREATE TABLE IF NOT EXISTS `simpleform1` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
`address` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`country` varchar(50) NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

--
-- Dumping data for table `simpleform1`
--

INSERT INTO `simpleform1` (`id`, `name`, `address`, `email`, `country`) VALUES
(1, 'osawa', 'JL. Ahmad Tamrin', 'osawa@yahoo.com', 'japan'),
(2, 'Miecky', 'Jl. Lubang Buaya', 'Miekey@yahoo.com', 'indonesia'),
(3, 'Gerson', 'Jl. Kertajaya', 'Gerson@gmail.com', 'Italia'),
(4, 'Tegar Hasadi', 'Jl. Tamrin', 'tegar@gmail.com', 'indonesia'),
(5, 'Toni', 'Jl. Bubutan', 'toni@yahoo.com', 'Italia'),
(6, 'Cassano', 'Jl Seomare', 'cassano@yahoo.com', 'Italia'),
(7, 'Dego M', 'Jl Ketapang', 'Dego@gmail.com', 'Brazil'),
(8, 'Sule M', 'Jl Waru', 'Sule@yahoo.com', 'Brazil'),
(9, 'Hemas', 'Jl Ponggok', 'hemas@yahoo.com', 'Korea');

After that we create a php file to connect to database.

2. koneksi.php

$nameserver = "localhost";
$username = "root";
$password = "";
$dbname = "defafe";//name of a database that I create
mysql_connect($nameserver,$username,$password)or die('error'.mysql_error());
mysql_select_db($dbname);
?>

After that we create a html file to call the javascript and css files

3. index.html




//include simplegridg.js

After that we create a javascript file to make a form
4. simplegridg.js

Ext.onReady(function(){

Ext.QuickTips.init();
// this script is the important points of this tutorial
var SimpleDataStore = new Ext.data.GroupingStore({
proxy: new Ext.data.HttpProxy({
url: 'simplegridg.php',
method: 'POST'
}),
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total'

},
[
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'address', type: 'string'},
{name: 'email', type: 'string'},
{name: 'country', type: 'string'}

]),
sortInfo:{field: 'country', direction: "ASC"},
groupField:'country' // this script is the important points of this tutorial ,  grouping by country
});

SimpleDataStore.load({params:{start:0,limit:6}});
var SimpleColumnModel = new Ext.grid.ColumnModel(
[
{
header: 'Id',
readOnly: true,
dataIndex: 'id',
width: 40,
hidden: false

},{
header: 'Name',
dataIndex: 'name',
width: 130

},{
header: 'Address',
dataIndex: 'address',
width: 200

},{
header: 'Email',
dataIndex: 'email',
vtype:'email',
width: 180
},
{
header: 'Country',
dataIndex: 'country',
width: 180
}]
);
SimpleColumnModel.defaultSortable= true;

var SimpleListingEditorGrid =  new Ext.grid.GridPanel({
title: 'Simple Grid',
store: SimpleDataStore,
cm: SimpleColumnModel,
//// this script is the important points of this tutorial , Compenent Grid grouping
view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
//......

frame:true,
collapsible: true,
animCollapse: true,
width:480,
height:290,

bbar: new Ext.PagingToolbar({
pageSize: 6,
store: SimpleDataStore,
displayInfo: true,
displayMsg: 'Displaying data {0} - {1} of {2}',
emptyMsg: "No data to display"
})

});

SimpleListingEditorGrid.render('form');

});

After that, we create a  php file to request data from the database and display it in the grid

5. simplegridg.php

include "koneksi.php";
include  "JSON.php";

$query = "SELECT * FROM simpleform1";    //this is the name of my table
$result = mysql_query($query);
$nbrows = mysql_num_rows($result);
$start = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
$end = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
$limit = $query." limit ".$start.",".$end;
$result = mysql_query($limit);

if($nbrows>0)
{
while($rec = mysql_fetch_array($result))    {

$arr[] = $rec;
}
$jsonresult = JEncode($arr);
echo '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
}
else
{
echo '({"total":"0", "results":""})';
}

// Encodes a SQL array into a JSON formated string
function JEncode($arr){
if (version_compare(PHP_VERSION,"5.2","<"))
{
require_once("JSON.php"); //if php<5.2 need JSON class
$json = new Services_JSON();//instantiate new json object
$data=$json->encode($arr);  //encode the data in json format
} else
{
$data = json_encode($arr);  //encode the data in json format
}
return $data;
}

?>

Below is a screen shot of this tutorial

awal1

akhir2

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Incoming search terms for the article:

extjs grouping grid , extjs grid grouping , extjs b is null , extjs grouping , b is null extjs , groupingstore extjs , extjs groupingstore , extjs groupingstore example , ext grid grouping , ext data groupingstore example , grouping grid extjs , groupingstore paging , extjs grid grouping json , Ext data JsonReader example , grouping extjs , grouping in extjs grid , extjs groupingstore json , how to display point value in grid for extjs code , extjs groupingstore sample , extjs jsonreader tutorial , ext js grid grouping , extjs json encode , extJS this sortInfo field is null , extjs jsonreader example , extjs how to check json with ext data jsonreader , php grid with grouping , extjs json chart , grouped grid extjs , extjs using the grouptexttpl , extjs row header , extjs table border , extjs table headers , extjs upload php , extjs json echo output , grouping files ext js , grouping grid in extjs , remove gruping from grid in extjs , php SELECT * FROM $this , php json extjs , new Ext PagingToolbar for Ext data GroupingStore , new Ext data HttpProxy grouping , jsonreader GroupingStore php , jsonreader extjs example with grid , JSONReader extjs , json reader tutorial , json reader extjs , json encoded format in ext js , how to do grouping in extjs , Header grouping Extjs , GroupingStore json ext extjs themes , extjs file upload , extjs theme , extjs upload , extjs upload file , extjs grid checkbox , extjs tutorial , extjs login , extjs grid paging , extjs login form extjs checkbox readonly , checkbox row extjs , upload image extjs mysql , extjs file upload tutoriel , tutoriel extjs , extJS checkbox datastore , FileUploadField extjs documentation , icon-user-delete extjs , getSelectionModel() getSelections(); , register extjs application 

14 Responses to “Tutorial Extjs: Grouping”

  1. Evan Y says:

    Wow,,, keren pk bhs inggris mas…
    javascript ya… menarik nih,,,
    apalagi pake contoh codinganx jg… mantap,,,
    wah, kyk’e Q hrs byk bljr dr smpyn kl mw mbangun web nih… he3x.. :)

  2. faisal says:

    baru belajar juga kok dek……,,, heheheheh

  3. roms gameboy says:

    nice share, thank you..
    keep it up…

  4. faisal says:

    thanks…

  5. pr1a_punya_sel3ra says:

    Knp kok pindah bro??

  6. faisal says:

    I want to learn to write using the English

  7. Thanks for the full example, it’s always very useful to see things done from start to finish. Good job!

  8. Richa Gupta says:

    How can I disable a checkBox which is displayed in header.I am using checkBoxSelection Model

    thanks and Reagrds
    Richa

  9. Neels says:

    I have used this example but I am getting error like b is null .
    Any one have an idea?

  10. mbahsomo says:

    Betul – betul Pecinta ExtJs

  11. faisal says:

    kamu juga ya sob

  12. Akhmad A says:

    Thanks brader.. sangat membantu.. :D

  13. wonderfull, and don’t forget to app my fb.

  14. faisal says:

    thanks!!

Leave a Reply

Security Code: