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.