删除 CI Flexigrid 中选定行的问题
我遇到了一些奇怪的问题。显然,我想删除我在 Flexigrid 中选择的行。但是,当我选择行并单击“删除”按钮时,我只能看到实际选择了多少个项目,但由于某种原因,它没有传递行 ID。在 JS 代码中,当我运行一些测试时,我注意到 items[i].id 似乎未定义。也许有人可以告诉我我在这里做错了什么。这就是我的实现的样子:
JS 代码
function test(com,grid)
{
if (com=='Select All')
{
$('.bDiv tbody tr',grid).addClass('trSelected');
}
if (com=='DeSelect All')
{
$('.bDiv tbody tr',grid).removeClass('trSelected');
}
if (com=='Delete')
{
if($('.trSelected',grid).length>0){
if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')) {
var items = $('.trSelected',grid);
var itemlist ='';
for(i=0;i<items.length;i++){
itemlist+= items[i].id+",";
}
$.ajax({
type: "POST",
url: "<?=site_url("/ajax/deletec");?>",
data: "items="+itemlist,
success: function(data){
$('#flex1').flexReload();
alert(data);
}
});
}
} else {
return false;
}
}
控制器
function index()
{
$colModel['id'] = array('id',40,TRUE,'left',1);
$colModel['admins.name'] = array('Name',180,TRUE,'left',0);
$colModel['admins.email'] = array('Email',180,TRUE,'left',1);
$colModel['admins.password'] = array('Password',180,TRUE,'left',0);
$colModel['edit'] = array('Edit',30,TRUE,'left',1);
/* Aditional Parameters */
$gridParams = array(
'width' => 'auto',
'height' => 400,
'rp' => 15,
'rpOptions' => '[10,15,20,25,40]',
'pagestat' => 'Displaying: {from} to {to} of {total} items.',
'blockOpacity' => 0.5,
'title' => 'Admins of Fact10best.com',
'showTableToggleBtn' => true
);
/* Buttons, which will appear above this list */
$buttons[] = array('Delete','delete','test');
$buttons[] = array('separator');
$buttons[] = array('Select All','add','test');
$buttons[] = array('DeSelect All','delete','test');
$buttons[] = array('separator');
$buttons[] = array('Add Admin','add','test');
//Build js
//View helpers/flexigrid_helper.php for more information about the params on this function
$grid_js = build_grid_js('flex1',site_url("admin/admin_control/list_admins"),$colModel,'admins.name','asc',$gridParams,$buttons);
$data['js_grid'] = $grid_js;
$data['list_details'] = null;
$data['users_fact'] = null;
$this->load->view('admin_panel/admin_content', $data);
}
/* List displayer for index() */
//---------------------------------------------------------------------------------------------------------------
public function list_admins()
{
$valid_fields = array('id','admins.name','admins.email', 'admins.password');
$this->flexigrid->validate_post('admins.name','asc',$valid_fields);
$records = $this->admin_login_model->list_flexigrid_admins();
$record_items = array();
foreach ($records['records']->result() as $row)
{
$record_items[] =
array (
$row->id,
$row->name,
$row->email,
$row->password,
'<a href='.site_url("admin_login/edit_admin/".$row->id).'>
<img src="http://www.fact10best.com/system/application/views/images/magnify.png" style="border:none;">
</a>',
);
}
//Print please
$this->output->set_header($this->config->item('json_header'));
$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
}
视图
<table id="flex1" style="display:none"></table>
I'm encountering some weird problem. Apparently, I would like to delete the rows of my choice in flexigrid. However, when I'm selecting the rows and click 'Delete' button I only see how many items I actually selected but, for some reason, it's not passing the rows ids. In JS code when I'm running some test I noticed that items[i].id appears to be undefined. Perhaps someone could tell me what I'm doing wrong here. This is how my implementation looks like:
JS code
function test(com,grid)
{
if (com=='Select All')
{
$('.bDiv tbody tr',grid).addClass('trSelected');
}
if (com=='DeSelect All')
{
$('.bDiv tbody tr',grid).removeClass('trSelected');
}
if (com=='Delete')
{
if($('.trSelected',grid).length>0){
if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')) {
var items = $('.trSelected',grid);
var itemlist ='';
for(i=0;i<items.length;i++){
itemlist+= items[i].id+",";
}
$.ajax({
type: "POST",
url: "<?=site_url("/ajax/deletec");?>",
data: "items="+itemlist,
success: function(data){
$('#flex1').flexReload();
alert(data);
}
});
}
} else {
return false;
}
}
Controller
function index()
{
$colModel['id'] = array('id',40,TRUE,'left',1);
$colModel['admins.name'] = array('Name',180,TRUE,'left',0);
$colModel['admins.email'] = array('Email',180,TRUE,'left',1);
$colModel['admins.password'] = array('Password',180,TRUE,'left',0);
$colModel['edit'] = array('Edit',30,TRUE,'left',1);
/* Aditional Parameters */
$gridParams = array(
'width' => 'auto',
'height' => 400,
'rp' => 15,
'rpOptions' => '[10,15,20,25,40]',
'pagestat' => 'Displaying: {from} to {to} of {total} items.',
'blockOpacity' => 0.5,
'title' => 'Admins of Fact10best.com',
'showTableToggleBtn' => true
);
/* Buttons, which will appear above this list */
$buttons[] = array('Delete','delete','test');
$buttons[] = array('separator');
$buttons[] = array('Select All','add','test');
$buttons[] = array('DeSelect All','delete','test');
$buttons[] = array('separator');
$buttons[] = array('Add Admin','add','test');
//Build js
//View helpers/flexigrid_helper.php for more information about the params on this function
$grid_js = build_grid_js('flex1',site_url("admin/admin_control/list_admins"),$colModel,'admins.name','asc',$gridParams,$buttons);
$data['js_grid'] = $grid_js;
$data['list_details'] = null;
$data['users_fact'] = null;
$this->load->view('admin_panel/admin_content', $data);
}
/* List displayer for index() */
//---------------------------------------------------------------------------------------------------------------
public function list_admins()
{
$valid_fields = array('id','admins.name','admins.email', 'admins.password');
$this->flexigrid->validate_post('admins.name','asc',$valid_fields);
$records = $this->admin_login_model->list_flexigrid_admins();
$record_items = array();
foreach ($records['records']->result() as $row)
{
$record_items[] =
array (
$row->id,
$row->name,
$row->email,
$row->password,
'<a href='.site_url("admin_login/edit_admin/".$row->id).'>
<img src="http://www.fact10best.com/system/application/views/images/magnify.png" style="border:none;">
</a>',
);
}
//Print please
$this->output->set_header($this->config->item('json_header'));
$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
}
View
<table id="flex1" style="display:none"></table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经发现了我的问题的原因。我会将其发布在这里,以防其他人遇到类似的问题。在flexigrid库中有一行特定的行:
我不明白为什么这条行被注释掉。我删除了评论,现在它就像魅力一样。
I've discovered the reason of my problem. I will post it here in case someone else will have similar problem. In the flexigrid library there is a specific line:
I don't understand why this line was commented out. I removed the comment and it works like charm right now.
在 flexigrid 选项中:
函数 doCommand 获取选定的行以及按哪个字段排序:
In the flexigrid options:
The function doCommand get the selected rows and by which field is sorted: