A table based grid - please let me know if I'm reinventing the wheel here

Hi Folks,
Since I did not find an editable grid that suits my requirement (of
being light weight and editable) I started writing
my own - here’s what I’m trying -

A helper function like this that renders a grid -

def mygrid(row,col)
table=’


table << “”
1.upto col do |c|
table << “”
end
table << “”
1.upto row do |r|
table << “”
1.upto col do |c|
table << “”
end
table << “”
end
table << “
Col #{c}
<input id=“col_#{r}_#{c}” style=“border:none;”
type=“text”
onkeydown=“handle_keyboard(event,#{r},#{c},#{row})”>

end

And the supporting js function -

function handle_keyboard(e,r,c,max_r){
var code=e.keyCode;
if(code==13 || code==40){
r=r+1;
if(r>max_r)r=1;
id=‘col_’+r+""+c;
document.all[id].focus()
}
if(code==38){//up
r=r-1;
if(r<1)r=1;
id='col
’+r+"_"+c;
document.all[id].focus()
}
}

I intend to add Ajax to it - but before that I wanted to understand if
I’m doing all this and there’s a better solution already out there.


Regards,
Kashyap

C K Kashyap wrote:

Hi Folks,
Since I did not find an editable grid that suits my requirement (of
being light weight and editable) I started writing
my own - here’s what I’m trying -

A helper function like this that renders a grid -
[…]

I would suggest that you might want to put this into a couple of
partials instead. Or at least use content_tag.

[…]

    table << "<td><input id=\"col_#{r}_#{c}\" style=\"border:none;\"

Why not use a class instead of an inline style?

type=“text”
onkeydown=“handle_keyboard(event,#{r},#{c},#{row})”>"

Get your JS out of your HTML. It belongs in a separate file.

[…]


Regards,
Kashyap

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs