EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Stefan B. on February 25, 2015, 02:24:25 AM



Title: edatagrid - how can i give dynamic request parameters to the destroyUrl
Post by: Stefan B. on February 25, 2015, 02:24:25 AM
We use edatagrid with the destroyUrl. But now we must give some dynamic request parameters to the destroyUrl.
But there is no event 'onBeforeDestroy' to change the destroyUrl before send the request to the server.

How can we give some dynamic request parameters to the destroyUrl?


Title: Re: edatagrid - how can i give dynamic request parameters to the destroyUrl
Post by: stworthy on February 25, 2015, 10:08:58 AM
Only the 'id' parameter can be posted to server when destroying a row. The 'id' value will be retrieved from the 'idField' field.


Title: Re: edatagrid - how can i give dynamic request parameters to the destroyUrl
Post by: Stefan B. on February 26, 2015, 01:14:38 AM
OK that means we must manipulate the destroyUrl before destroy the row like this
Code:
destroyUrl: 'delete.do?secoondId=abc'


Title: Re: edatagrid - how can i give dynamic request parameters to the destroyUrl
Post by: lcsft on March 02, 2015, 12:25:42 AM
Hi,

I don't use the datagrid edit extension, so I have a special column with a delete icon on it, and I am able to use a custom function to get the selected row and pass arbitrary parameters to the server.
For the grid column:
Code:
 
{field: 'dummy_action', title: 'Manage', align:'center', width: '8%',
formatter:function(value,row,index)
{
    return '<a style="margin: 0 5px;" href="javascript:void(0)" onclick="deleteRowFunction(this, '+row.id+');"><img src="..." alt="" class="icon_del" /></a> '
}
and basics of the deleteRowFunction function
Code:
function deleteRowFunction(el, rowid)
{
    // If you need the grid, then you can query from the current element up
    var grid = jQuery(el).closest('.datagrid-wrap').find('.datagrid-f:first');
   
    // If you need you can get the row index (not row id !!) starting from where the icon is
    var tr = $(el).closest('tr.datagrid-row');
    var rowIndex = parseInt(tr.attr('datagrid-row-index'));
   
    // I use the destroyUrl (without the edatagrid.js) which you can get from the grid by
    var opts = jQuery(grid).datagrid('options');
    // and opts.destroyUrl is the param you specified at the grid init
   
    // Now get the full row from the grid
    var row = jQuery(grid).datagrid('getSelected');

    // And finally you can either append to the destroyUrl any param since you have the full row
    // Or if you have a database id in the dataset, then you don't need to query the full row, just use the rowid parameter to append it
    // to the destroyUrl, eg.
   var destroyUrl = opts.destroyUrl + '?id=' + rowid;
}

Hope this helps.