PDA

View Full Version : Grid Link



border9
25 Apr 2008, 4:12 AM
What im trying to do is when you click this link, i need it to call a php script which it does but its throwing an error saying im doing it wrong. not sure where.


{ header: "Delete",
width: 8,
sortable: true,
dataIndex: 'delete',
renderer: function(quote) {
return '<a href = # onClick="deletequote("quote")">Remove</a>';
}}],

Thats what in the grid, The command it calls is as follows.


function deletequote(quote)
{
input_box=confirm("Are you sure you want to delete this?");
if (input_box==true)
{
window.location="php/deletequote.php?id=" + quote;
}
else
{
return false;
}
}

What i need it to do is i need it to ask me if i want to remove / change the area that this SQL command belongs. but its telling me that its syntax error. any ideas? Thanks

Animal
25 Apr 2008, 4:22 AM
Do not do that. Use this: http://dev.extjs.com/deploy/dev/docs/?class=Ext.grid.GridPanel&member=cellclick

FAQ: http://extjs.com/learn/Ext_FAQ#How_can_I_add_click_handlers_to_specific_Grid_cells.3F

border9
25 Apr 2008, 4:29 AM
I figured it was something like that but im having a hell of a time finding any kinda example that shows a link involved in that, i need an active link that i can call or a button or some sort of something to know that its a link.

follow what im saying? Thanks

Animal
25 Apr 2008, 4:39 AM
Have you followed those links?

That is what you should be using.

Animal
25 Apr 2008, 4:40 AM
Or this: http://extjs.com/forum/showthread.php?t=29961

border9
25 Apr 2008, 5:16 AM
Ok, so ive tried a diffrent approch, im trying to do it the same way i delete an item, but instead of deleting i want it to update and change a specific SQL Query item.

IE:
Javascript

function handleRemove() {

var selectedKeys = mainquotesGrid.selModel.selections.keys;
if(selectedKeys.length > 0)
{
Ext.MessageBox.confirm('Message','Do you really want to remove quote?', removeRecord);
}
else
{
Ext.MessageBox.alert('Message','Please select at least one item to delete');
}
};
function removeRecord(btn) {
if(btn=='yes')
{

var selectedRows = mainquotesGrid.selModel.selections.items;
var selectedKeys = mainquotesGrid.selModel.selections.keys;
var encoded_keys = Ext.encode(selectedKeys);

Ext.Ajax.request( //alternative to Ext.form.FormPanel? or Ext.BasicForm.submit
{
waitMsg: 'Saving changes...',
url: 'php/gridoptions.php',
params: {
task: "remove",
quote: encoded_keys,
key: quote_number
},

callback: function (options, success, response) {
if (success) {
Ext.MessageBox.alert('OK',response.responseText);
var json = Ext.util.JSON.decode(response.responseText);
Ext.MessageBox.alert('OK',json.remove_count + ' record(s) deleted.');

} else{
Ext.MessageBox.alert('Sorry, please try again. [Q304]',response.responseText);
}
},

failure:function(response,options){
Ext.MessageBox.alert('Warning','Oops...');
},
success:function(response,options){

mainquoteStore.reload();
}
}
);
};
};

Thats the Javascript, here is the PHP


function removeData()
{
$arr = $_POST['quote'];
$key = $_POST['key'];
$count = 0;

if (version_compare(PHP_VERSION,"5.2","<"))
{
require_once("JSON.php");
$json = new Services_JSON();
$selectedRows = $json->decode(stripslashes($arr));
} else
{
$selectedRows = json_decode(stripslashes($arr));
}
foreach($selectedRows as $row_id)
{
$id = (integer) $row_id;
$query = 'UPDATE `'.$table.'` SET `'.$field.'` = \''.$value.'\' WHERE `'.$key.'` = '.$id;
$result = mysql_query($query); /
if ($result) $count++;
}

if ($count) { /
$cb = isset($_GET['callback']) ? $_GET['callback'] : '';

$response = array('success'=>$count, 'remove_count'=>$count);

if (version_compare(PHP_VERSION,"5.2","<"))
{
$json_response = $json->encode($response);
} else
{
$json_response = json_encode($response);
}
echo $cb . $json_response;
} else {
echo '{failure: true}';
}
}

The Area in red is the query, but when its the normal delete function it works like a charm but it seems like when its not deleting and is only updating it causes the javascript or the php script somehwere to not be able to read the checked items, it goes through all the motions and then says unidentified items removed instead of (#) of items removed which inreturn causes the script to fail and not remove anything. Any ideas? Thanks

Animal
25 Apr 2008, 5:24 AM
So what does the returned packet look like in Firebug?

border9
25 Apr 2008, 5:27 AM
Returns the IDs its supose to, thats whats really making me wana beat my head on a wall, its returning everythings its supose to so its something to do with the PHP, but as far as my knowledge goes i dont see anything wrong there. all i did was change the php command from my Delete function so instead of deleting it just changes the field set. any ideas?

Animal
25 Apr 2008, 5:40 AM
I dont understand.

border9
25 Apr 2008, 6:13 AM
When i click the Checks, and i click on the button that is suposse to remove the IDs and change thier status, which would move them off that grid, when it sends it it sends the proper IDs and the proper command, but something isnt flowing right on the php side, all i did which worked before is i changed it from fully deleting the ID to just updating the ID and now it doesnt work.

i cant show you much code then what i displayed already because what i displayed is all the code.

any ideas? Thanks

Animal
25 Apr 2008, 6:50 AM
You're asking me about problems in your PHP?

border9
25 Apr 2008, 9:23 AM
NO the PHP is fine, im asking if you have any idea what might be getting lost between the Javascript and the PHP

Animal
25 Apr 2008, 10:13 AM
That's what Firebug is for.

mjlecomte
25 Apr 2008, 2:07 PM
Returns the IDs its supose to, thats whats really making me wana beat my head on a wall, its returning everythings its supose to so its something to do with the PHP, but as far as my knowledge goes i dont see anything wrong there. all i did was change the php command from my Delete function so instead of deleting it just changes the field set. any ideas?

If you want help you need to explain this better.

The php script you posted is not returning "IDs".

Check and post here what firebug shows getting sent to server. Check and post here what firebug shows coming back from server. You appear to have a communication error at the interface, you need to coordinate what's getting sent to your server.

border9
26 Apr 2008, 12:07 AM
Ok, thank you that was all i was asking, because firebug said that when i check and tell it to remove the ids its Displaying the IDs checked, as well as the specific ID of the item that its supose to remove.

Something is getting lost between the javascript and the php and isnt allowing it to just UPDATE the ID and only wants to delete it.

The script works when i run it with just the delete function, but when i tried to change it around so that the items being checked wherent removed from teh database but renamed it didnt like it.

ill see what firebug says and get back to you.
Thanks