srivatsavap / jquery-datatables-editable

Automatically exported from code.google.com/p/jquery-datatables-editable
0 stars 0 forks source link

Ajax arguments for add/edit/delete #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
my need was to supply additional arguments to ajax requests for add/edit and 
delete, something like action=tablefoobar-add, action=tablefoobar-edit, 
action=tablefoobar-del.

For the add action, nothing of impossible: just added an hidden input to add 
form with name "action" and value as tablefoobar-add. All ok.
For the delete action, there's the oDeleteProperties option that meet my needs: 
during initialization, pass "oDeleteParameters": {"action": "tablefoobar-del"} 
option.
For the edit, I tried to pass "submitdata" with the "action" parameter within 
the aoColumns definition but it broke the submitdata logic (the function..). 
After hacking the code a bit, I think that the best solution is to add a 
oEditParameters option that hold the parameters passed to jeditable 
"submitdata" option.
To do this I've added:
1) (line 488) New oEditParameters on defaults ( oEditParameters: {}, )
2) (line 208) Modified the oDefaultEditableSettings submitdata function, 
joining the oEditParameters obj:
                    return $.extend({
                        "id": id,
                        "rowId": rowId,
                        "columnPosition": columnPosition,
                        "columnId": columnId,
                        "columnName": sColumnName,
                    }, properties.oEditParameters);
3) Simply pass  "oEditParameters": {"action": "tablefoobar-edit"} on 
initialization like oDeleteParameters and all cells will pass that parameter to 
ajax.

That's all. I worked on version 1.3 of your script, I think that this simple 
option must be included in next stable version and that a page on the Docs that 
explain how to pass addictional parameters on ajax requests will be useful.

Hi,
Ezio

Original issue reported on code.google.com by ezio.bo...@gmail.com on 30 Nov 2011 at 5:40

GoogleCodeExporter commented 9 years ago
Hi,

Thanks, for this but are you using the latest version of plugin that is placed 
on the site. 1.3 is just last version package with offline examples. There is 
similar functionality on this page 
http://jquery-datatables-editable.googlecode.com/svn/trunk/inline-edit-parameter
s.html that uses the latest version of plugin 2.0.7.

Could you let me know is this same as the functionality you have implemented?

Thanks,
Jovan

Original comment by joc...@gmail.com on 9 Feb 2012 at 9:47

GoogleCodeExporter commented 9 years ago

Original comment by joc...@gmail.com on 9 Feb 2012 at 10:19

GoogleCodeExporter commented 9 years ago
Hello, I've been trying to implement this passing of the parameters but while 
using oDeleteParameters. The paramaters are posting fine. But I'm not sure how 
to grab the row 'id' of the selected row. Please help.

Original comment by simon...@gmail.com on 17 Feb 2012 at 1:02

GoogleCodeExporter commented 9 years ago
I don't understand this. Row id is automatically sent to delete page see 
http://jquery-datatables-editable.googlecode.com/svn/trunk/delete-record.html . 
Where you want to grab it?

Jovan

Original comment by joc...@gmail.com on 17 Feb 2012 at 8:12

GoogleCodeExporter commented 9 years ago
Hi Jovan,
 I need to get the rowId within oUpdateParameters. After getting the rowId, I need to get the value of one more td for that particular row. 

for example : if user is editing the <td>second</td> then I need to get the 
value of 
<td>first</td> as well and send it to the server.
<tr id="8">
   <td>first</td>
   <td>second</td> 
</tr>

Thanks,
Raj

Original comment by v.rajku...@gmail.com on 22 Feb 2012 at 9:45

GoogleCodeExporter commented 9 years ago
You can in fnOnEditing take this input, find TR parent that surrounds it, find 
first TD in that TR, and put that value in some local variable.
Then you can in oUpdateParameters define additional parameter that is function 
that read local variable and add it to the input set parameters. I would look 
like:

var currentKey = '';

$('#example').dataTable().makeEditable({
                                            fnOnEditing: function(input)
                {   currentKey = input.parents("tr").children("td:first").text();
                                                        return true;
                                                        },
                                                oUpdateParameters: {
                                                            key: function(){ return currentKey; } 
                                                }

});

I have created example in 
http://jquery-datatables-editable.googlecode.com/svn/trunk/issue91.html. Ignore 
the error message and see parameters that are sent to server-side in Ajax call. 
You will see that parameter parameter key is always first cell of the row.

Jovan

Note I think that this issue can be closed. I will add this example on wiki if 
you confirm that this is what you need.

Original comment by joc...@gmail.com on 24 Feb 2012 at 4:37

GoogleCodeExporter commented 9 years ago
Thank you very much Jovan. This solves my issue now. Appreciate your quick 
response.

Raj

Original comment by v.rajku...@gmail.com on 24 Feb 2012 at 5:16

GoogleCodeExporter commented 9 years ago
I have added this example in the how to wiki page 
http://code.google.com/p/jquery-datatables-editable/wiki/HowTo

Original comment by joc...@gmail.com on 24 Feb 2012 at 8:57

GoogleCodeExporter commented 9 years ago
Hi Jovan, 
 The fix is working for all the columns except the first one (which is the key). For example if I edit rendering engine column in the example you have provided the key is going in as empty. All other columns send the key correctly.
I should have tested thoroughly.

Thanks,
Raj

Original comment by v.rajku...@gmail.com on 27 Feb 2012 at 5:07

GoogleCodeExporter commented 9 years ago
I should add more information on why the above is needed.
I want to validate the duplicate entry of the primary key. If the key exists in 
the table already, we have to disallow users entering that information again. 
May be there is another way to do this. 

Thanks
Raj

Original comment by v.rajku...@gmail.com on 27 Feb 2012 at 5:10