This works pretty simply:
document.observe('dom:loaded',function(){
var editr = function(evt){
var elm = Event.element(evt);
Event.stopObserving('data','click',editr);
elm.update('<input type="text" id="ed_' + elm.id + '"
name="edit['
+ elm.id + ']" value="' + elm.innerHTML + '" />');
$('ed_' + elm.id).activate().observe('blur',function(evt){
elm.update($F('ed_' + elm.id));
//send your ajax update here
$('data').observe('click',editr);
})
}
$('data').observe('click',editr);
});
I am sure it could be written more simply, and someone said that
there was a better way to get the x/y than using a unique id for each
editable td. My table is thus:
<table cellspacing="0" id="data">
<tr><th> </th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</
th></tr>
<tr><th>1</th><td id="A1">Data</td><td id="B1">Data</td><td
id="C1">Data</td><td id="D1">Data</td><td id="E1">Data</td></tr>
<tr><th>2</th><td id="A2">Data</td><td id="B2">Data</td><td
id="C2">Data</td><td id="D2">Data</td><td id="E2">Data</td></tr>
<tr><th>3</th><td id="A3">Data</td><td id="B3">Data</td><td
id="C3">Data</td><td id="D3">Data</td><td id="E3">Data</td></tr>
<tr><th>4</th><td id="A4">Data</td><td id="B4">Data</td><td
id="C4">Data</td><td id="D4">Data</td><td id="E4">Data</td></tr>
</table>
Walter
On Apr 17, 2008, at 6:51 PM, Gareth Evans wrote:
> Greg,
>
> It wouldn't be hard to roll-your-own but the technique I would use
> would depend on the database schema that was going to be storing
> the data.
> I don't know if you want to have all the cells editable by default,
> but if you do, you'd need a lot of observers. You might be able to
> avoid this by attaching and detaching observers dynamically - i
> don't think bubbling works on blur/focus though?
> I would personally do a periodical executor which serialized the
> table and saved it if it's changed rather than relying on onBlur
> events to save individual cells - this way you don't have too many
> ajax requests hitting your server.
> You could have the onblur events keeping an internal class up to
> date which was then sync'd with the server and use a big cookie to
> provide instant saving.
> Just some random musings...
>
> Gareth
>
> On Fri, Apr 18, 2008 at 10:26 AM, nlloyds <[EMAIL PROTECTED]> wrote:
>
> On Apr 16, 8:22 am, greghauptmann <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Any recommendations re a component/plugin/javascript library to give
> > me an in-line editable table (spreadsheet like support), like google
> > spreadsheets?
> >
> > Tks
>
> TableKit (http://www.millstream.com.au/upload/code/tablekit/) might be
> a good starting point.
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---