manuelgtz / jquery-datatables-editable

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

a function passed to oUpdateData gets called without context #91

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to pass a parameter to the update call which indicates the row i'm in. 
Unfortunatelly i can't access the cell/row/table in a function passed to 
oUpdateData. 

As a workaround i modified the submitdata - function to add such a key when a 
property "iKeyColumn" is given (see attached file) and this property set to 
null in defaults (iKeyColumn: null)

Perhaps this modification is useful to include in future versions (i think it 
should be fully backwards compatible).

Original issue reported on code.google.com by ge...@engel-mail.net on 10 Feb 2012 at 8:15

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

I'm not sue that I understand why you want to include this. Key/Id of the 
record should be placed in the id attribute of the TR tag and it is sent as id 
parameter to the server-side.
Why you want to place it in the some cell to? I can add this but as far as I 
see this will be same information as id.

Jovan

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

GoogleCodeExporter commented 9 years ago
Hi Jovan,
there are two causes: First, the (translation-) key is part of the data. In my 
table i'm holding translation data and if one encounters an untranslated key, 
the key itself is displayed. So searching for it and changing it's 
translation(s) is a valid use case.  
That doesn't prevent me from writing this key as an tr-id as well. This job 
does Tapestry 4. Unfortunatelly i'm stuck to this. The table is build using 
@For which does not allow me to specify some of the records data as id (or at 
least i did not figure out). Would be duplicated information anyway, so taking 
the information from a column looks somewhat cleaner to me. 

Thanks for your effort,
Georg

Original comment by ge...@engel-mail.net on 11 Feb 2012 at 6:41

GoogleCodeExporter commented 9 years ago
Hi George,

I think that I understand what you want to achieve, however, I would like to 
avoid adding this additional parameter. Could you try some different approach? 
As example 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.

This way you can send any information you need to servers side without 
modifying plugin.

Let me know does this helps you.

Thanks,
Jovan

Original comment by joc...@gmail.com on 12 Feb 2012 at 10:41

GoogleCodeExporter commented 9 years ago
Hi Jovan,
thank you very much for figuring this out, it works perfectly for me. 

Greetz from Switzerland,
Georg

Original comment by e...@imis.ch on 13 Feb 2012 at 7:08

GoogleCodeExporter commented 9 years ago
I'm glad that I helped.

Regards,
Jovan

Original comment by joc...@gmail.com on 13 Feb 2012 at 5:41