Tutorial Extjs: Download File

I think this tutorial is easy, and maybe many programmer alredy know how to make it.

Main point of this tutorial is how to get file id in the grid. After that, we call the name of the file that we will to download.

In this section, we use the database from the previous tutorial: Upload file and image using extjs, so here we will try to download a file that was saved in the previous tutorial: upload file and image using extjs


Below is the screen shot of this tutorial:

download

To create this tutorial, several files that need is as follows:

1. create html file to call javascipt and css files






2. create javascipt file to make form download

Ext.onReady(function(){
Ext.QuickTips.init();
var simplestore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy ({
url:'show1.php',
method: 'POST'
}),
reader: new Ext.data.JsonReader ({
root: 'results',
totalProperty: 'total',
id: 'id',
fields: [
'id','Filename','Fileconten','photo','date'
]
}),
sortInfo:{field: 'id', direction: "ASC"}

});

simplestore.load({params:{start:0,limit:6}});

var SimpleColumnModel = new Ext.grid.ColumnModel(
[
{
header: 'ID',
dataIndex: 'id',
width: 50

},
{
header: 'File Name',
dataIndex: 'Filename',
width: 130

},{
header: 'File Conten',
dataIndex: 'Fileconten',
width: 250,
renderer: function(value, cell){
cell.css = "cell";
return value;
}

},
{
header: 'Date',
dataIndex: 'date',
width: 150,
renderer: Ext.util.Format.dateRenderer('m/d/Y'),
hidden: false
}]
);
SimpleColumnModel.defaultSortable= true;

var SimpleGrid =  new Ext.grid.EditorGridPanel({
title: 'Simple Grid',
store: simplestore,
cm: SimpleColumnModel,
enableColLock:false,
frame:true,
width:600,
height: 250,
selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
bbar: new Ext.PagingToolbar({
pageSize: 6,
store: simplestore,
displayInfo: true,
displayMsg: 'Displaying data {0} - {1} of {2}',
emptyMsg: "No data to display"
}),

tbar: [{
//this is main point of this section tutorial
text: 'Download',
iconCls:'download',
handler:function(){
var m = SimpleGrid.getSelections();
if(m.length > 0){
location.href = './artikel/'+ m[0].get('Fileconten');

}
else{
Ext.MessageBox.alert('Message', 'Please choose a file that you want');
}
}}
]

});

var myPanel = new Ext.Panel({
autoScroll :true,
renderTo:'download',
items:[
SimpleGrid
]
});

});

3. finally create php file to dasplay data

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

$query = "SELECT * FROM uploadf";
$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;
//echo $limit;
$result = mysql_query($limit);

if($nbrows>0)
{
while($rec = mysql_fetch_array($result))    {
$rec['date']=codeDate($rec['date']);
$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;
}
function codeDate ($date) {
$tab = explode ("-", $date);
$r = $tab[1]."/".$tab[2]."/".$tab[0];
return $r;
}

?>

Thanks for your attention. Download Soure code

Random articles:

Related article by another person

Reblog this post [with Zemanta]

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

Incoming search terms for the article:

extjs tutorial , tutorial extjs , extjs download file , belajar extjs , extjs form dan php , extjs file download , extjs php json download example , extjs file upload tbar , extjs ImageButton , extjs download file button , extjs ajax file download , tutorial on extjs , extjs store proxy tutorial , extjs get file width , extjs get grid cell values , extjs GridPanel php json , tutorial belajar java script , extjs gridpanel to xls , script php menampilkan foto yang telah di upload ke database , retrieve data ke checkbox pake extjs , menampilkan data extjs , tutorial proxy: new Ext data HttpProxy , file download fild extjs , extjs php session tutorial , tutorial extj , extjs simplestore json , extjs fileupload download JSON , download file inpo , EditorGridPanel extjs example , EditorGridPanel tutorial , Ext Ajax request upload file , ext js upload file json , Ext SimpleStore example sortInfo , ext-js editorgridpanel checkbox , explode data extjs 3 , extjs choose file , extjs database tutorial , extjs download , extjs download button , extjs download button post , extjs download file from form , extjs file upload field width , extjs file-upload php , extjs files upload php json , descargar ext MessageBox extjs themes , extjs file upload , extjs theme , extjs upload , extjs upload file , extjs grid checkbox , extjs tutorial , extjs login , extjs login form , extjs grid paging site:defafe com , site:defafe com , site:defafe com , data base grid checkbox extjs , how to check password and confirm password in php , login window for extjs , tbar checkbox extjs , checkbox tbar grid extjs , extjs access session , find expanded rows in ext grid 

20 Responses to “Tutorial Extjs: Download File”

  1. faisal says:

    Bro.. ????????

  2. gemini says:

    Wah kalau mau download dimana yah… tutorialnya

  3. faisal says:

    saya kirim email aja mas

  4. jogisilalahi says:

    mantap banget mas..

  5. jogisilalahi says:

    ajari saya penggunaan JSON la mas, belum ludeng,
    via japri aja yah mas ke if07035@gmail.com
    salam,

  6. dochwo says:

    Thanks for all your tutorials!

    Very good work!

  7. afnaz says:

    mas,,bole minta dowloadan tutorial ext js ga??saya baru belajar ext js…
    thx before…

  8. faisal says:

    OK, tunggu mas nanti saya bikin link untuk mendowload semua tutorial yang ada di blog ini, terima kasih telah berkunjung di website ini

  9. newbie says:

    boleh request tutorial tentang nampilin gambar di form setelah ada aksi row click?? bingung?
    terima kasih, tutorial2nya bermanfaat banget. di tunggu tutorial selanjutnya. salam.

  10. Agus Akhmad says:

    mas.. pernah pake Ext.Ajax.request g??

    klo kita mo download file xls bsa g sh pake Ext.Ajax.request??

    thanks.. :D

  11. afnaz says:

    mas,,boleh minta downloadan tutorial extjs ga?? saya baru belajar niy n nyari tutorialnya susah bgt…

    thx a lot yah

  12. Tabish says:

    thanks a lot brother for these tutorials

  13. faisal says:

    me too

  14. faisal says:

    bisa sob

  15. Yusni says:

    Bro… kode untuk ambil file dari database yang bisa di download dimana ya????

    Thanks for yur attention..

  16. faisal says:

    di dtutorial sebelumny ada bro

  17. rosi says:

    Masalahnya gini saya punya table inventaris dan ketika button “Detail Data” diklik maka akan tampil hanya data dari Table History(Form ke-2) yg kode pada table history = kode pd table inventaris.
    Nah, gmn caranya mas??? di bawah ini masih tampil semua…
    Untuk menampilkan data dr database saya pake Ext.data.GroupingStore.
    saya sudah tambahkan gini…
    var m = data_inventaris_grid.getSelections();
    var GrupStore_data_history = new Ext.data.GroupingStore({
    proxy: new Ext.data.HttpProxy({
    url: ‘data_history.php?kode=’+ m[0].get(’kode’),
    method: ‘POST’
    }),
    baseParams:{task: “LISTING”},
    reader: new Ext.data.JsonReader({
    root: ‘results’,
    totalProperty: ‘total’,
    id: ‘id’,
    fields: ['id','tgl','history','kode']
    }),
    sortInfo:{field: ‘id’, direction: “ASC”}
    });
    GrupStore_data_history.load({params:{start:0,limit:10}});

    KET : data_inventaris_grid adalah Ext.grid.GridPanel dari table inventaris
    baseParams “LISTING “ mengacu pada sql query pada data_history.php
    dengan $SQL = mysql_query(“SELECT * FROM history WHERE kode = $_GET(“kode”)”);
    tapi tetep tampil smw..pake listeners: {load: handleActivate}, juga gak bisa Maz.KENAPA ya maz…???
    Dan gimana solusinya…????
    Best Regards

  18. faisal says:

    please check this script “url: ‘data_history.php?kode=’+ m[0].get(’kode’),”

    and you can check the previous tutorial about editing data in the grid. and I apologize if it’s too late to answer.

  19. faisal says:

    thanks for all

Leave a Reply

Security Code: