question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error with beforeColumn and afterColumn methods.

See original GitHub issue

(A) what you did

I wanted to add a column at the beginning of the table, so n my CustomCrudController I added a column like this:

$this->crud->addColumn(['label' => "label", 'type' => "text", 'name' => 'name'])->beforeColumn('firstColumn');

(B) what you expected to happen I expected the Column “Name” to be shown at the beginning of the tabel, just before the “firstColumn” column.

© what happened

ErrorException in Columns.php line 92:
array_splice() expects parameter 2 to be long, string given

(D) what have you already tried to fix it? I already submited a PR: https://github.com/Laravel-Backpack/CRUD/pull/472 Changed the beforeColumn and afterColumn methods on /CRUD/src/PanelTraits/Columns.php:

    /**
     * Moves the recently added column to 'before' the $target_col.
     *
     * @param $target_col
     */
    public function beforeColumn($target_col)
    {
        foreach ($this->columns as $column => $value) {
            if ($value['name'] == $target_col) {
                **$offset = array_search($column, array_keys($this->columns));**
                array_splice($this->columns, **$offset**, 0, [array_pop($this->columns)]);
                break;
            }
        }
    }

    /**
     * Moves the recently added column to 'after' the $target_col.
     *
     * @param $target
     */
    public function afterColumn($target_col)
    {
        foreach ($this->columns as $column => $value) {
            if ($value['name'] == $target_col) {
                **$offset = array_search($column, array_keys($this->columns));**
                array_splice($this->columns, **$offset + 1**, 0, [array_pop($this->columns)]);
                break;
            }
        }
    }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tabacitucommented, Jun 1, 2017

Hi @gmedeiros ,

Yup, done in a different commit and issue. All works now, take a look.

Cheers!

0reactions
dmagurcommented, Jun 1, 2017

@tabacitu, cool, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

can you specify "after column" with liquibase addColumn?
With Liquibase 3.1 there are new "afterColumn", "beforeColumn" and "position" attributes on the column tag.
Read more >
TreeColumns cannot be arranged during runtime | DevExpress ...
Hi Valdemar, I have shifted up the DoLayoutChanged call (after column deletion - before column addition). This way everything works well. Thanks for...
Read more >
CREATE MASK statement - IBM
The CREATE MASK statement creates a column mask at the current server. A column mask specifies the value to be returned for a...
Read more >
Calc: vlookup produces Er:502 error after column 10 - English
I am trying to post a value from a different sheet using Vlookup and a dropdown list. =(VLOOKUP($A$15,cstmr,11,0)) The dropdown cell is A15....
Read more >
ALTER TABLE statement (Microsoft Access SQL)
Use the DAO Create methods instead. ... Attempting to apply this restriction more than once restuls in a run-time error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found