Empty Database won't add new row.

20 views
Skip to first unread message

Waynex

unread,
Oct 17, 2010, 5:28:24 AM10/17/10
to TableGear
Hi Again,
I seem to have found another bug... I'm good at breaking stuff LOL!

So there are two problems around this area.

Problem 1: When there is no data in the database the class=primary_key
for th & tr elements for the Id column dosen't get assigned (currently
I am using the css ".primary_key{display:none;}" to hide them) It
would be great if this columns would get that from the table schema
even when there is no data.
Also when you go to add a new row what occurs is that all the input
rows are moved to the left by one column which means that you can't
obviously add data in the right column.

Problem 2: When using Pagination settings, if you delete all the rows
from the table then refresh the page, or if you have no data in the
table to begin with then the "Add A Row" link doesn't appear. (I
turned off Pagination to confirm this was the issue).

Question: Last thing I promise, how would I be able to keep the "Add A
Row" always visible? The users I'm developing this for would not
really understand being able to add a new row just by moving down to
the next row, as far as usability goes I think being able to do this
is a must!

Thanks again for your time and effort, I hope my feed back helps to
build a better product!

Waynex

Waynex

unread,
Oct 17, 2010, 7:01:05 AM10/17/10
to TableGear
Sorry I forgot to add the link to the file that I'm working on

http://wayneandfarrah.com/dev/critical_systems/public/markov.php

Andrew Plummer

unread,
Oct 18, 2010, 12:34:35 PM10/18/10
to tabl...@googlegroups.com
Ok, try these out (overwrite what you've got now):

http://github.com/andrewplummer/TableGear/raw/master/lib/include/TableGear1.6.1.php

I'm not going to publish a new release for this one on the off chance that you find another bug ;)

Andrew

Waynex

unread,
Oct 20, 2010, 4:15:30 AM10/20/10
to TableGear
Hi Again,
Your fix worked for the problem of empty the database and the primary
column ID... but I found some further issue I believe are related so
here they are:

1. When you have a table that's paginated the primary_key does not get
set for the header
see: http://wayneandfarrah.com/dev/critical_systems/public/markov.php

2. When you exceed the row limit (10 in this case) that you set for
pagination, the pagination only happens when you refresh the page.
This is not a bug as such though I feel it makes sense for it to
function this way, this may be a feature for which I have a few
suggestions should I post them here or over at user voice?
http://tablegear.uservoice.com/forums/61705-general

On Oct 19, 3:34 am, Andrew Plummer <plummer.and...@gmail.com> wrote:
> Ok, try these out (overwrite what you've got now):
>
> http://github.com/andrewplummer/TableGear/raw/master/lib/include/Tabl...http://github.com/andrewplummer/TableGear/raw/master/lib/javascripts/...

Andrew Plummer

unread,
Oct 20, 2010, 4:27:58 AM10/20/10
to tabl...@googlegroups.com
Let me look into it... shouldn't be all that hard to implement that.

Also I forgot to mention before that I also added an option called "showAddNewRow".
Try that out and you should always see the add new row link!

Wayne Allan

unread,
Jan 17, 2011, 6:22:51 AM1/17/11
to tabl...@googlegroups.com, plummer...@gmail.com
Hey Andrew,

I posted something on Google Groups not sure if it worked or what or whether you need to approve the comment, but just in case you didn't I made some bug fixes to TableGear.php. I have posted the function below with comments around the change I made. It fixes the problem where when using pagination the primary_key and auto_increment classes don't get added to the header. So here it is.

Regards
Wayne

  function _fetchHeaders()
  {
    $headers = array();
    if($this->form && $this->editable) array_push($headers, array("field" => "EDIT", "html" => $this->headers["EDIT"], "attrib" => array("class" => $this->_checkColumnClass("EDIT"))));
    if(count($this->data) > 0){
      $firstRow = reset($this->data);
      $column = 1;
      foreach($firstRow["data"] as $field => $data){
        $sortable = $this->_testForOption("sortable", $field, $column) ? true : false;
        $sortType = $this->_getSortType($field);
        $class = $this->_addClass("sortable", null, $sortable);
        $class = $this->_addClass($sortType, $class);
        if($this->primaryKeyColumnsByName[$field]){
          $class = $this->_addClass("primary_key", $class);
          if($this->primaryKeyColumnsByName[$field]["auto"]){
            $class = $this->_addClass("auto_increment", $class);
          }
        }
        if($this->headers[$field]) $userHeader = $this->headers[$field];
        elseif($this->headers[$column]) $userHeader = $this->headers[$column];
        else $userHeader = null;
        $html = null;
        if(is_array($userHeader)){
          $html = $userHeader["html"];
          $class = $this->_addClass($userHeader["class"], $class);
        } elseif(is_string($userHeader)){
          $html = $userHeader;
        }
        if(!$html && $this->autoHeaders) $html = $this->_autoFormatHeader($field);

        // Match sorting field
        preg_match('/^\w+/', $this->database["sort"], $match);
        $sort = $match[0];
        $desc = preg_match('/desc\s*$/i', $this->database["sort"]) > 0;

        $carat = array("tag" => "span", "attrib" => array("class" => "carat"));
        if($sort == $field){
          if($desc){
            $desc = null;
            $carat["html"] = "▼";
          } else {
            $desc = "true";
            $carat["html"] = "▲";
          }
        }
        $html = array(array("tag" => "span", "html" => $html), $carat);
        if($this->pagination && $this->pagination["totalPages"] != 1){
          $href = $this->_modifyURIParams(array("sort" => $field, "desc" => $desc, "page" => null));
          $link = array("tag" => "a", "html" => $html, "attrib" => array("href" => $href));

          //Changes by wkall...@gmail.com
          //There was a bug in this section, the primary_key and auto_increment tags weren't getting added
          //when pagination was in use and more than one page

          $header = array("html" => $link, "attrib" => array("class" => $class, "id" => $userHeader["id"]));

         //End of Changes by wkall...@gmail.com
        } else {
          $header = array("html" => $html, "attrib" => array("class" => $class, "id" => $userHeader["id"]));
        }
        array_push($headers, $header);
        $column++;
      }
    } elseif($this->connection){
      if(!$this->database["table"]) return;
      $columns = $this->query("SHOW COLUMNS FROM " . $this->database["table"]);
      if(!$columns) return;
      foreach($columns as $column){
        $field = $column["Field"];
        $header["field"] = $field;
        $class = "";
        if($this->autoHeaders) $header["html"] = $this->_autoFormatHeader($field);
        else $header["html"] = $field;
        if($column["Key"] == "PRI"){
          $class = $this->_addClass("primary_key", $class);
        }
        if(stripos($column["Extra"], "auto_increment") !== false){
          $class = $this->_addClass("auto_increment", $class);
        }
        $header["attrib"] =  array("class" => $class);
        array_push($headers, $header);
      }
    }
    if($this->allowDelete && $this->form) array_push($headers, array("field" => "DELETE", "html" => $this->headers["DELETE"], "attrib" => array("class" => $this->_checkColumnClass("DELETE"))));
    return $headers;
  }
Reply all
Reply to author
Forward
0 new messages