1

I have used Dynamic rows in product edit form.

Here is my DataProvider class code

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Ui\Component\DynamicRows;
class Attachments extends AbstractModifier
{
  private $arrayManager;
  public function __construct(
   ) {
     $this->arrayManager = $arrayManager;
   }

   $dynamicRows['arguments']['data']['config'] = [
        'addButtonLabel' => __('Add Row'),
        'componentType' => DynamicRows::NAME,
        'itemTemplate' => 'record',
        'renderDefaultRecord' => false,
        'columnsHeader' => true,
        'additionalClasses' => 'admin__field-wide',
        'dataScope' => 'downloadable',
        'deleteProperty'=> 'is_delete',
        'deleteValue' => '1',
        'currentPage' => 1,
        'pageSize' => 10
    ];

    return $this->arrayManager->set('children/record', $dynamicRows, $this->getRecord());
  }

In the above code 'pageSize' is limiting the rows for one page, is there any way where we can set the limit to 10?

I am just looking for the code maximum we have to show only 10 rows, can we show any error message if it crosses 10?

Please someone guide me on this. Thank you!!

1 Answer 1

3

Try to extend the default javascript for dynamicRows component vendor/magento/module-ui/view/base/web/js/dynamic-rows/dynamic-rows.js and assign it to your component with

'component' => 'Your_Module/js/extend-dynamic-rows',

Here try to override the function processingAddChild like magento does in the core vendor/magento/module-ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js where you could see

processingAddChild: function (ctx, index, prop) {
    if (this._elems.length > this.pageSize) {
        // insert here your error message
    }
    ...
}
5
  • hi @LucScu, Thank you for the answer possible to update the code for extending this file?
    – Manjunath
    Feb 1, 2021 at 10:33
  • Hi @Manjunath, what do you mean?
    – LucScu
    Feb 1, 2021 at 10:52
  • hi @LucScu,I just asked how to extend that js file? using require-js? I am just doing it,
    – Manjunath
    Feb 1, 2021 at 11:01
  • Like i wrote in the answer take a look to dynamic-rows-grid.js that extends dynamic-rows.js. Just copy it and customize it to your module and use this new custom js as component of your ui component.
    – LucScu
    Feb 1, 2021 at 14:56
  • hi @LucScu Thank you, can you help me on this magento.stackexchange.com/questions/330548/…
    – Manjunath
    Feb 4, 2021 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.