PDA

View Full Version : [SOLVED]Removing items from GridPanel



Czapla
11 Feb 2010, 10:55 AM
Hello ext Community

So here is my problem, i made a simple button with function, that i found in other thread. My firebug don't show me any errors so i think the code is fine.
I think my php file is also correct [tested query in phpmyadmin]. But items from my GridPanel are not disappear.

SOLVED

added params now its looks like grid.remove(params{})

Cheers

Czapla
12 Feb 2010, 2:32 AM
Still need help on this

Cheers

conorarmstrong
12 Feb 2010, 2:36 AM
at first glance, delete_srodek.php is not returning anything. in your js code srodki_delete_data is a JsonStore expecting some Json output from your php

Czapla
12 Feb 2010, 3:26 AM
Ok i found one mistake [still didn't work, but...]
I need to use the same data like in selected items from my gridpanel. So EXT will know what must be remove. I decide i will remove field using srt_kod [because itis set to UNIQUE].

here is my data store


var srodki_data = new Ext.data.JsonStore({
totalProperty: 'total',
root: 'results',
url: 'warstwy/logika/wyswietl_srodki.php',
fields: ['srt_nazwa', 'srt_kod', 'grsrt_kod', 'srt_nrewid', 'klsrt_symbol', 'srt_datauzyt', 'srt_datalikw']
});


Here is my GridPanel


var wyswietl_srodki = new Ext.grid.GridPanel({
renderTo: 'wyswietl_srodki',
store: srodki_data,
columns: [
{header: 'Pe\u0142na nazwa', width: 100, sortable: true, dataIndex: 'srt_nazwa'},
{header: 'Kod', width: 100, sortable: true, dataIndex: 'srt_kod'},
{header: 'Kod Grupy', width: 100, sortable: true, dataIndex: 'grsrt_kod'},
{header: 'Numer Ewidencyjny', width: 100, sortable: true, dataIndex: 'srt_nrewid'},
{header: 'K\u015aT', width: 100, sortable: true, dataIndex: 'klsrt_symbol'},
{header: 'Data przyj\u0119cia', width: 100, sortable: true, dataIndex: 'srt_datauzyt'},
{header: 'Data likwidacji', width: 100, sortable: true, dataIndex: 'srt_datalikw'}
],
stripeRows: true,
height:600,
//width:900,
title:'\u015arodki Trwa?e - Ksi?ga Inwentarzowa',
bbar: new Ext.PagingToolbar({
pageSize: 10, // data to display
store: srodki_data,
displayInfo: true,
displayMsg: 'Wy\u015bwietlono {0} - {1} z {2}',
emptyMsg: "Brak wpisów do wy\u015bwietlenia"
}),
tbar: new Ext.Toolbar({
items: [{
xtype: 'tbbutton',
text: 'Dodaj',
handler: function() {
okno_modal.show();
}
},{
xtype: 'tbbutton',
text: 'Edytuj',

handler: function() {
var gridrecord = wyswietl_srodki.getSelectionModel().getSelected();
if (!gridrecord){
alert('\u017ble');
} else {
alert(gridrecord.id);
}
}
},{
xtype: 'tbbutton',
text: 'Usu\u0144',
store: srodki_data,
url: 'logika/usun_srodek.php',

handler: function() {
var srt_kod = wyswietl_srodki.getSelectionModel().getSelected();
if (!srt_kod){
return false;
} else {
Ext.MessageBox.confirm('Komunikat', 'Czy napewno chcesz usun\u0105? ten rekord?' , srt_kod);
var rekord = wyswietl_srodki.store.getAt(srt_kod[0]);
wyswietl_srodki.store.remove(rekord);
//success: true;
}
}
}]
})
});
[php]

php file
[php]
$result = mysql_query ("DELETE FROM srodki WHERE srt_srtid = '".$_POST['srt_kod']."'") or die ('{"success":"false"}');


cheers

carol.ext
12 Feb 2010, 7:05 AM
It would help if you would explain a bit more.

Are you getting to the point where you have records displaying in the grid, you select one or more and press the delete button? Is your handler getting called? Step through it in the debugger.

Doesn't getSelectionModel().getSelected(); return a record? RowSelectionModel API (http://www.extjs.com/deploy/dev/docs/?class=Ext.grid.RowSelectionModel)

Hopefully the javascript you posted is just snippets from your code because jslint.com doesn't like it.


handler: function () {
var index = list.getSelectionModel().getSelected();
if (!index) {
return false;
} else {
var rekord = list.store.getAt(index[0]);
list.store.remove(rekord);
}
}

Animal
12 Feb 2010, 7:10 AM
@OP: use code tags!

not php, code

Czapla
12 Feb 2010, 8:12 AM
Hello
I had moderate mode on all my posts, dunno why - early bumping, bad gramma?

Anyway
The point is i used wrong data.JStore, i should use the same data array as is in the select query.

So here is new data store


var srodki_data = new Ext.data.JsonStore({
totalProperty: 'total',
root: 'results',
url: 'warstwy/logika/wyswietl_srodki.php', //acctualy here is a select query
fields: ['srt_nazwa', 'srt_kod', 'grsrt_kod', 'srt_nrewid', 'klsrt_symbol', 'srt_datauzyt', 'srt_datalikw']
});




var wyswietl_srodki = new Ext.grid.GridPanel({
renderTo: 'wyswietl_srodki',
store: srodki_data,
columns: [
{header: 'Pe\u0142na nazwa', width: 100, sortable: true, dataIndex: 'srt_nazwa'},
{header: 'Kod', width: 100, sortable: true, dataIndex: 'srt_kod'},
{header: 'Kod Grupy', width: 100, sortable: true, dataIndex: 'grsrt_kod'},
{header: 'Numer Ewidencyjny', width: 100, sortable: true, dataIndex: 'srt_nrewid'},
{header: 'K\u015aT', width: 100, sortable: true, dataIndex: 'klsrt_symbol'},
{header: 'Data przyj\u0119cia', width: 100, sortable: true, dataIndex: 'srt_datauzyt'},
{header: 'Data likwidacji', width: 100, sortable: true, dataIndex: 'srt_datalikw'}
],
stripeRows: true,
height:600,
//width:900,
title:'\u015arodki Trwa?e - Ksi?ga Inwentarzowa',
bbar: new Ext.PagingToolbar({
pageSize: 10, // data to display
store: srodki_data,
displayInfo: true,
displayMsg: 'Wy\u015bwietlono {0} - {1} z {2}',
emptyMsg: "Brak wpisów do wy\u015bwietlenia"
}),
tbar: new Ext.Toolbar({
items: [{
xtype: 'tbbutton',
text: 'Dodaj',
handler: function() {
okno_modal.show();
}
},{
xtype: 'tbbutton',
text: 'Edytuj',

handler: function() {
var gridrecord = wyswietl_srodki.getSelectionModel().getSelected();
if (!gridrecord){
alert('\u017ble');
} else {
alert(gridrecord.id);
}
}
},{
xtype: 'tbbutton',
text: 'Usu\u0144',
store: srodki_data,

handler: function() { //this is my mesterious code i was copied from another thread
var index = wyswietl_srodki.getSelectionModel().getSelected();
if (!index){
return false;
} else {
Ext.MessageBox.confirm('Komunikat', 'Czy napewno chcesz usun\u0105? ten rekord?' , index);
var srt_kod = wyswietl_srodki.store.getAt(index[0]);
wyswietl_srodki.store.remove(srt_kod);
}
}
}]
})
});

I decide i will deleting items using srt_kod [i was set as UNIQUE].

my php file


$result = mysql_query ("DELETE FROM srodki WHERE srt_srtid = '".$_POST['srt_kod']."'") or die ('{"success":"false"}');


@carol.ext
I want to select one record and press the button.
Debbuger dont show me anything.


HERE IS THE SAMPLE OF MY APPLICATION:

https://prac.us.edu.pl/~wkurpani/

Cheers

Czapla
13 Feb 2010, 12:37 AM
So removing is working, but when i refresh the page all records are display.
This is because of i dont know how to pass my parm to php file.

i tried
baseParams: {index: 'srt_srtid'}

but its not work



var srodki_usun_data = new Ext.data.JsonStore({
url: 'warstwy/logika/usun_srodek.php',
root: 'index',
baseParams: {index: 'srt_srtid'},
idProperty: 'id',
fields: ['srt_srtid']
});

var wyswietl_srodki = new Ext.grid.GridPanel({
renderTo: 'wyswietl_srodki',
store: srodki_data,
columns: [
{id:'srt_srtid', header: "id", width: 30, sortable: true, dataIndex: 'srt_srtid'},
{header: 'Pe\u0142na nazwa', width: 100, sortable: true, dataIndex: 'srt_nazwa'},
{header: 'Kod', width: 100, sortable: true, dataIndex: 'srt_kod'},
{header: 'Kod Grupy', width: 100, sortable: true, dataIndex: 'grsrt_kod'},
{header: 'Numer Ewidencyjny', width: 100, sortable: true, dataIndex: 'srt_nrewid'},
{header: 'K\u015aT', width: 100, sortable: true, dataIndex: 'klsrt_symbol'},
{header: 'Data przyj\u0119cia', width: 100, sortable: true, dataIndex: 'srt_datauzyt'},
{header: 'Data likwidacji', width: 100, sortable: true, dataIndex: 'srt_datalikw'}
],
stripeRows: true,
height:600,
//width:900,
title:'\u015arodki Trwa?e - Ksi?ga Inwentarzowa',
bbar: new Ext.PagingToolbar({
pageSize: 10, // data to display
store: srodki_data,
displayInfo: true,
displayMsg: 'Wy\u015bwietlono {0} - {1} z {2}',
emptyMsg: "Brak wpisów do wy\u015bwietlenia"
}),
tbar: new Ext.Toolbar({
items: [{
xtype: 'tbbutton',
text: 'Dodaj',
handler: function() {
okno_modal.show();
}
},{
xtype: 'tbbutton',
text: 'Edytuj',

handler: function() {
var gridrecord = wyswietl_srodki.getSelectionModel().getSelected();
if (!gridrecord){
alert('\u017ble');
} else {
alert(gridrecord.id);
}
}
},{
xtype: 'tbbutton',
iconCls: 'remove',
text: 'Usu\u0144',
store: srodki_usun_data,
triggerAction: 'all',

handler: function() {
var index = wyswietl_srodki.getSelectionModel().getSelected();
if (index){
//Ext.MessageBox.confirm('Komunikat', 'Czy napewno chcesz usun\u0105? rekord ' + index.id + ' ?');
var rekord = srodki_data.getAt(index[0]);
srodki_data.remove(index);

} else {
return false;
}
}
}]
})
});




var srodki_usun_data = new Ext.data.JsonStore({
url: 'warstwy/logika/usun_srodek.php',
root: 'index',
fields: ['srt_srtid']
});


[code]
$result = mysql_query ("DELETE FROM srodki WHERE srt_srtid = '".$_POST['index']."'") or die ('{"success":"false"}');
[code]

Cheers

Czap1a
13 Feb 2010, 1:33 AM
Mod don't want to add my post here and i need help ASAP.



handler: function() {
var index = wyswietl_srodki.getSelectionModel().getSelected();
if (index){
//Ext.MessageBox.confirm('Komunikat', 'Czy napewno chcesz usun\u0105? rekord ' + index.id + ' ?');
var rekord = srodki_data.getAt(index[0]);
srodki_data.remove(index);

} else {
return false;
}
}


I have 2 problems:
first: the code is always triggered before message have show
second i dont know how to pass a id of index to my php file
i tried:


var srodki_usun_data = new Ext.data.JsonStore({
url: 'warstwy/logika/usun_srodek.php',
root: 'index',
baseParams: {index: 'srt_srtid'},
idProperty: 'id'
//fields: ['srt_srtid']
});
[code]
Here is a sample of my code:
[code]
var wyswietl_srodki = new Ext.grid.GridPanel({
renderTo: 'wyswietl_srodki',
store: srodki_data,
columns: [
{id:'srt_srtid', header: "id", width: 30, sortable: true, dataIndex: 'srt_srtid'},
{header: 'Pe\u0142na nazwa', width: 100, sortable: true, dataIndex: 'srt_nazwa'},
{header: 'Kod', width: 100, sortable: true, dataIndex: 'srt_kod'},
{header: 'Kod Grupy', width: 100, sortable: true, dataIndex: 'grsrt_kod'},
{header: 'Numer Ewidencyjny', width: 100, sortable: true, dataIndex: 'srt_nrewid'},
{header: 'K\u015aT', width: 100, sortable: true, dataIndex: 'klsrt_symbol'},
{header: 'Data przyj\u0119cia', width: 100, sortable: true, dataIndex: 'srt_datauzyt'},
{header: 'Data likwidacji', width: 100, sortable: true, dataIndex: 'srt_datalikw'}
],
stripeRows: true,
height:600,
//width:900,
title:'\u015arodki Trwa?e - Ksi?ga Inwentarzowa',
bbar: new Ext.PagingToolbar({
pageSize: 10, // data to display
store: srodki_data,
displayInfo: true,
displayMsg: 'Wy\u015bwietlono {0} - {1} z {2}',
emptyMsg: "Brak wpisów do wy\u015bwietlenia"
}),
tbar: new Ext.Toolbar({
items: [{
xtype: 'tbbutton',
text: 'Dodaj',
handler: function() {
okno_modal.show();
}
},{
xtype: 'tbbutton',
text: 'Edytuj',

handler: function() {
var gridrecord = wyswietl_srodki.getSelectionModel().getSelected();
if (!gridrecord){
alert('\u017ble');
} else {
alert(gridrecord.id);
}
}
},{
xtype: 'tbbutton',
iconCls: 'remove',
text: 'Usu\u0144',
store: srodki_usun_data,
//triggerAction: 'all',

handler: function() {
var index = wyswietl_srodki.getSelectionModel().getSelected();
if (index){
//Ext.MessageBox.confirm('Komunikat', 'Czy napewno chcesz usun\u0105? rekord ' + index.id + ' ?');
var rekord = srodki_data.getAt(index[0]);
srodki_data.remove(index);

} else {
return false;
}
}
}]
})
});


HERE IS THE SAMPLE OF MY APPLICATION:

https://prac.us.edu.pl/~wkurpani/