Git Product home page Git Product logo

Comments (1)

halfpastfouram avatar halfpastfouram commented on September 22, 2024

I've had this happen to me too. It doesn't happen in the unit test, though.

After some digging I found that it's fairly easy to reproduce:

// First create a hidden column:
$idColumn = new Column\Select('id');
$idColumn->setHidden(true);
$dataGrid->addColumn($idColumn);

// Then create an action column with an action in it:
$actionColumn = new Column\Action('id');
$actionButton = new Column\Action\Button();
$actionButton->setLabel('My buton');
$actionButton->setLink('/edit/' . $actionButton->getColumnValuePlaceholder($dataGrid->getColumnByUniqueId('id')));
$actionColumn->addAction($actionButton);

I'm using the default renderer ('BootstrapTable') and the generated link is now /edit/, missing the hidden id column.

Now, let's see what happens when I stop hiding the id column:

$idColumn->setHidden(false);

The result is still /edit/ instead of /edit/1 (assuming the value of that column would be 1. Why? Because the action column shouldn't be named 'id'. But if you leave the parameter of new Column\Action() blank you might run into a TypeError. Now, fixing this is easy: just set the unique id manually on the id column:

// First create a hidden column:
$idColumn = new Column\Select('id');
$idColumn->setUniqueId('id');
$idColumn->setHidden(true);
$dataGrid->addColumn($idColumn);

// Then create an action column with an action in it:
$actionColumn = new Column\Action();
$actionButton = new Column\Action\Button();
$actionButton->setLabel('My buton');
$actionButton->setLink('/edit/' . $actionButton->getColumnValuePlaceholder($dataGrid->getColumnByUniqueId('id')));
$actionColumn->addAction($actionButton);

The generated output now contains the correct url: /edit/1.

Now, I don't quite understand why the TypeError appears, but I've found that this will prevent that error from appearing.

from zfc-datagrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.