I have created the block grid in admin product edit page section, I have added a text field in that grid column using below addcolumn method.

                'header' => __('Position'),
                'type' => 'number',
                'index' => 'position',
                'editable' => true,
                'filter' => false,
                'sortable' => false,

Now I want to add an Ajax call when the admin user tries to change the inline state, enter image description here

When the admin user wants to change the position from row number three to row number one, at that moment I want an ajax call in the text field of the position column.

can I someone help me to how to add Ajax call in block grid?

1 Answer 1


I am not sure but you can follow this steps may be help: 1). If custom grid you can define require-config.js and with the help of it you can do it. 2). In core you can simple add JS file in layout. For more information follow this: Add JS in adminhtml 3). After that capture onclick and do the needful.

  • Hi Aniket, I have already tried this solution but I unable to get values on the enter key. added phtml and tried with script.
    – user73267
    Jun 17, 2023 at 8:57
  • Can you share your code?
    – Ankit
    Jun 18, 2023 at 7:04
  • { 'use strict'; jQuery(document).ready(function(){ jQuery("input[name='position']").keypress(function(event){ var keycode = (event.keyCode ? event.keyCode : event.which); if(keycode == '13') { var numItems = $('.col-id-position').length; var movePosition = this.value; var existingPosition = $(this).closest("td").find("span.admin__grid-control-value").text(); if(movePosition > numItems){ alert('Please put the value in between of 1 to '+numItems); } } event.stopPropagation(); }); });
    – user73267
    Jun 18, 2023 at 7:29
  • I have created block and added template file and testing purpose added hello message, template work fine. tried to add above script in that template but simple alert hello is not working on enter key.. same script I have tried to create normal php form with html and there this script work fine. due to text limit I have not added script and require function in above script let me know if I miss anything, thanks in advance :)
    – user73267
    Jun 18, 2023 at 7:38
  • Also checked there is no any error message in console
    – user73267
    Jun 18, 2023 at 7:39

Your Answer

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

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