在w2ui网格中,我要在删除以下行后选择网格线。这是我的JavaScript代码:
w2ui[ grd_obj.grid_id ].on( 'delete', function( event )
{
event.onComplete = function()
{
var min_ind = 100000
var sel = w2ui[ grd_obj.grid_id ].getSelection()
for ( var r in sel )
{
var ind = w2ui[ grd_obj.grid_id ].get( sel[ r ].recid, true )
min_ind = Math.min( ind, min_ind )
}
if ( event.phase == 'after' )
{
var ind = w2ui[ grd_obj.grid_id ].prevRow( min_ind )
var rcd = w2ui[ grd_obj.grid_id ].records[ ind ]
w2ui[ grd_obj.grid_id ].selectNone()
w2ui[ grd_obj.grid_id ].select( { recid: rcd[ grd_obj.grid_table.grid_key ], column: 0 } )
}
}
})
我找不到删除后如何重新获得“重新加载”的方法...调试,我发现在“ after”事件中,.select()正在起作用,并且可以看到已选择了需要的记录。但是,据我所知,“删除”触发了网格的“重新加载”,并且地雷选择消失了……:(
如何解决这个问题?
服务器端数据库(mysql + php)。
预先感谢...
已编辑(已解决):
找到解决方案。不确定这是否很好,但是否可以正常工作...做了类似的事情: 在自己的网格对象中添加“ grid_setRec”参数。然后在“删除”事件中分配此值
w2ui[ grd_obj.grid_id ].on( 'delete', function( event )
{
event.onComplete = function()
{
var min_ind = 10000
var sel = w2ui[ grd_obj.grid_id ].getSelection()
for ( var r in sel )
{
var ind = w2ui[ grd_obj.grid_id ].get( sel[ r ].recid, true )
min_ind = Math.min( ind, min_ind )
}
if ( w2ui[ grd_obj.grid_id ].total > 0 )
{
var ind = w2ui[ grd_obj.grid_id ].prevRow( min_ind )
var rcd = w2ui[ grd_obj.grid_id ].records[ ind ]
grd_obj.grid_setRec = rcd[ grd_obj.grid_table.grid_key ]
}
}
})
在“加载”事件中看到此值:
w2ui[ grd_obj.grid_id ].on( 'load', function( event )
{
event.onComplete = function()
{
if ( grd_obj.grid_setRec != '' )
{
reload_callBack( grd_obj, grd_obj.grid_setRec )
grd_obj.grid_setRec = ''
}
}
})
reload_callBack函数我通常使用“ reload”事件回调,然后将新记录添加到网格中。
function reload_callBack( grd_obj, rcd_id )
{
setTimeout( function ()
{
w2ui[ grd_obj.grid_id ].selectNone()
w2ui[ grd_obj.grid_id ].select( { recid: rcd_id, column: 0 } )
var ind = w2ui[ grd_obj.grid_id ].get( parseInt( rcd_id ), true )
w2ui[ grd_obj.grid_id ].scrollIntoView( ind )
}, 100 )
}
现在它可以按我的意愿工作了...:)
答案 0 :(得分:0)
解决了此问题,添加了自己的变量以进行重新加载。 “删除”事件触发“加载”事件。在这里,我看到是否需要使用回调函数重新选择它……