1

I have a add button in the datatable header where there is also a sort button. When I click on the add button it sorts the column and then opens a new page. I would like that when the add button is clicked that it opens a new page without sorting. How can I prevent this thank you for your help

Here is visual what it looks like

The add button in header

This is my html

<th><p><a id="open-new" class="btn" href="/fichaproveedor/AnadirEditar/0" ><i class="material-icons-add" title="Crear nuevo">add_box</i></a>Proveedor Id</p></th>

here is the complete generated html

<th class="sorting_asc" tabindex="0" aria-controls="proveedorTable" rowspan="1" colspan="1" style="width: 142px;" aria-label="add_boxProveedor Id: Activar para ordenar la columna de manera descendente" aria-sort="ascending"><p><a id="open-new" class="btn" href="/fichaproveedor/AnadirEditar/0"><i class="material-icons-add" title="Crear nuevo">add_box</i></a>Proveedor Id</p></th>

I believe that this problem is solvable whit javascript I have tried but failed to fix it. Thank you for your help.

1
  • 1
    Will you include your controller code? Is the url parameter '0' in /fichaproveedor/AnadirEditar/0 used to signal that it isn't sortable? Mar 31, 2020 at 14:44

1 Answer 1

1

I'm not sure if this actually works, since I haven't tried this out myself and only based this is on what I read on the internet myself. but I hope it helps.

$( "#open-new" ).click(function( event ) {
  event.stopPropagation();
});

From what I understand, when you click on the icon, it should only perform the given action, so open the new page, and with event.stopPropagation(); you'll stop any other events from happening.

If this actually stops the event but also stops it from opening a new page, try this:

$( "#open-new" ).click(function( event ) {
  event.stopPropagation();
  window.open("/fichaproveedor/AnadirEditar/0");
});
1
  • 1
    Thank you very much your first solution worked for me.
    – J.C
    Mar 31, 2020 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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