C K Kashyap
2009-Oct-09 06:00 UTC
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 border="1"
cellpadding="0">''
table << "<tr>"
1.upto col do |c|
table << "<th>Col #{c}</th>"
end
table << "</tr>"
1.upto row do |r|
table << "<tr>"
1.upto col do |c|
table << "<td><input id=\"col_#{r}_#{c}\"
style=\"border:none;\"
type=\"text\"
onkeydown=\"handle_keyboard(event,#{r},#{c},#{row})\"></td>"
end
table << "</tr>"
end
table << "</table>"
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
Marnen Laibow-Koser
2009-Oct-09 18:01 UTC
Re: A table based grid - please let me know if I''m reinventi
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})\"></td>"Get your JS out of your HTML. It belongs in a separate file. [...]> -- > Regards, > KashyapBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.