post by heruprambadi on Nov 9, 2023

Hello @johnny , i have question. I can show data with GCE, but some table can’t show the data.

This is my MySql :

CREATE TABLE `ppob_product` (
  `id` int NOT NULL,
  `product_name` varchar(22) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `ppob_product` (`id`, `product_name`) VALUES
(1, 'aa'),
(2, 'ss');

ALTER TABLE `ppob_product`
  ADD PRIMARY KEY (`id`);
COMMIT;

and this is my code :

public function index()
     {
         $crud = $this->_getGroceryCrudEnterprise();
         $crud->setTable('ppob_product');
         $crud->unsetCssTheme();
         //$crud->where(['per_info_personal.id_payroll >= ?' => 0]);
         $crud->setSubject('Produk', 'Daftar Produk');
         $crud->columns(['product_name']);
         
         $crud->setCsrfTokenName('_token');
         $crud->setCsrfTokenValue(csrf_token());
 
         $output = $crud->render();
         return $this->_showOutput($output);
     }

the data not showing :

can you help me @johnny ?

post by heruprambadi on Nov 9, 2023

i found the problem. Turns out it because my column name is “product_name”. I changed it to “name”, and now it show the data. Why is that?

post by heruprambadi on Nov 9, 2023

post by heruprambadi on Nov 10, 2023

post by johnny on Nov 11, 2023

Hello @heruprambadi ,

I believe the issue here if I have to blindly guess is that you use the same URL for different CRUD. Or you have tried the same one for index and then changed the table name. Just to make sure you can use the setUniqueId to make sure that your table is corresponding correctly.

See more a the documentation here: setUniqueId | Grocery CRUD - A PHP CRUD Generator Library

For example in your situation you can do this:

$crud->setUniqueId('ppob_product');

So the uniqueId will be your table name.

The reason that this is happening is that Grocery CRUD stores the column data into the local storage of the browser. And the only way to understand that this is the unique CRUD is by getting this uniqueId. If the unique id is not set then it is trying to have a uniqueID from the URL (which usually it is unique since we have one URL for each table)

Let me know if that worked for you.

Regards
Johnny

post by heruprambadi on Nov 12, 2023

post by johnny on Nov 13, 2023

Thank you @heruprambadi for letting me know. I will also have it a look to see if I can fix this issue in Grocery CRUD as well.

Regards
Johnny

post by johnny on Nov 14, 2023

Good news @heruprambadi ,

I am also finally able to reproduce the issue that you had so I will try to fix it for the next version.

Regards
Johnny

post by heruprambadi on Nov 14, 2023

post by johnny on Nov 14, 2023

setUniqueId is the best way actually. The less Grocery CRUD is trying to auto-guess, the better :slight_smile:

On the other hand, I have like 4 reports this month that this is happening so it is kind of annoying facing that to be honest as a developer :slight_smile:

In the future I want also to introduce the 'environment' = >'debug' configuration so you can have some helpful tools in case you would like to debug an issue that you have in development.

Thank you for your feedback by the way :slight_smile:

post by heruprambadi on Nov 14, 2023

post by johnny on Nov 14, 2023

Fair point @heruprambadi but I am trying to minimise the extra line if possible. I think in a future version it will have the url and the table name combined so this issue will go away even without the setUniqueId

I will keep you updated for this. For now you can do something like this:

    /**
     * Get everything we need in order to load Grocery CRUD
     *
     * @return GroceryCrud
     * @throws \GroceryCrud\Core\Exceptions\Exception
     */
    private function _getGroceryCrudEnterprise($tableName) {
        $database = $this->_getDatabaseConnection();
        $config = config('grocerycrud');

        $crud = new GroceryCrud($config, $database);

        // Don't forget those two below lines if you are 
        // using CSRF protection (enabled by default on Laravel 10)
        $crud->setCsrfTokenName('_token');
        $crud->setCsrfTokenValue(csrf_token());

        $crud->setTable($tableName);
        $crud->setUniqueId($tableName);
       
        return $crud;
    }

So you can always set the table and the uniqueId at the same time :wink:

1 / 12
Nov 2023