我需要第一个flexigrid进行ajax调用并加载其数据,当它完成时,第二个flexigrid将在轮到它时进行下一个ajax调用。 我怎么能这样做?
//FILL THE OFFERS GRID
jQuery("#OFFERS").flexigrid({
url: 'index.php?option=com_virtuemart&view=offers&task=getOffers&page=1&format=raw',
dataType: 'json',
singleSelect:true,
colModel : [
{display: 'id', name : 'id', width : 100, sortable : true, align: 'center'},
{display: 'startdate', name : 'startdate', width : 180, sortable : true, align: 'center'},
{display: 'enddate', name : 'enddate', width : 180, sortable : true, align: 'left'},
{display: 'product_name', name : 'product_name', width : 120, sortable : true, align: 'left'},
{display: 'discount_amount €', name : 'discount_amount', width : 100, sortable : true, align: 'left'},
{display: 'discount_percent %', name : 'discount_percent', width : 120, sortable : true, align: 'right'}
],
searchitems : [
{display: 'startdate', name : 'startdate', isdefault: true},
{display: 'enddate', name : 'enddate'},
{display: 'product_name', name : 'product_name'},
{display: 'discount_amount', name : 'discount_amount'},
{display: 'discount_percent', name : 'discount_percent'}
],
sortname: "id",
sortorder: "asc",
usepager: true,
title: 'Offer',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 900,
onSubmit: addFormData,
height: 200,
buttons: [
{name: 'Test', onpress: test}
]
});
//FILL THE PRODUCTS GRID
jQuery("#pnlProducts").flexigrid({
url: 'index.php?option=com_virtuemart&view=offers&task=getProducts&page=1&format=raw',
dataType: 'json',
singleSelect:true,
colModel : [
{display: 'id', name : 'id', width : 100, sortable : true, align: 'center'},
{display: 'name', name : 'name', width : 180, sortable : true, align: 'center'},
{display: 'price', name : 'price', width : 180, sortable : true, align: 'left'}
],
searchitems : [
{display: 'id', name : 'id', isdefault: true},
{display: 'name', name : 'name'},
{display: 'price', name : 'price'}
],
sortname: "id",
sortorder: "asc",
usepager: true,
title: 'Products',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 900,
onSubmit: addFormData,
height: 200,
buttons: [{name: 'Test2', onpress: test}]
});
答案 0 :(得分:1)
最后我找到了我的答案,为了确保我页面中的许多灵活组件能够正常工作而不会产生许多异步请求并导致浏览器混合数据,我可以在其上设置其属性并在那里传递函数。
//FILL THE OFFERS GRID
jQuery("#tblOFFERS").flexigrid({
url: 'index.php?option=com_virtuemart&view=offers&task=getOffers&page=1&format=raw',
dataType: 'json',
singleSelect:true,
colModel : [
{display: 'id', name : 'id', width : 100, sortable : true, align: 'center'},
{display: 'startdate', name : 'startdate', width : 180, sortable : true, align: 'center'},
{display: 'enddate', name : 'enddate', width : 180, sortable : true, align: 'left'},
{display: 'product_name', name : 'product_name', width : 120, sortable : true, align: 'left'},
{display: 'discount_amount €', name : 'discount_amount', width : 100, sortable : true, align: 'left'},
{display: 'discount_percent %', name : 'discount_percent', width : 120, sortable : true, align: 'right'}
],
searchitems : [
{display: 'startdate', name : 'startdate', isdefault: true},
{display: 'enddate', name : 'enddate'},
{display: 'product_name', name : 'product_name'},
{display: 'discount_amount', name : 'discount_amount'},
{display: 'discount_percent', name : 'discount_percent'}
],
sortname: "id",
sortorder: "asc",
usepager: true,
title: 'Offer',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 900,
onSubmit: addFormData,
height: 200,
onSuccess : fillTheNextGrid
buttons: [
{name: 'Test', onpress: test}
]
});
//FILL THE PRODUCTS GRID
function fillTheNextGrid(
jQuery("#tblPRODUCTS").flexigrid({
url: 'index.php?option=com_virtuemart&view=offers&task=getProducts&page=1&format=raw',
dataType: 'json',
singleSelect:true,
colModel : [
{display: 'id', name : 'id', width : 100, sortable : true, align: 'center'},
{display: 'name', name : 'name', width : 180, sortable : true, align: 'center'},
{display: 'price', name : 'price', width : 180, sortable : true, align: 'left'}
],
searchitems : [
{display: 'id', name : 'id', isdefault: true},
{display: 'name', name : 'name'},
{display: 'price', name : 'price'}
],
sortname: "id",
sortorder: "asc",
usepager: true,
title: 'Products',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 900,
onSubmit: addFormData,
height: 200,
buttons: [{name: 'Test2', onpress: test}]
});
)
答案 1 :(得分:0)
当我正在使用此控件时,我设法执行此操作以便稍后添加查询,但也保持排序,搜索和分页使用相同的代码。
jQuery(document).ready(function () {
//AUTO FILL THE OFFERS GRID
jQuery("#OFFERS").flexigrid({
url: 'index.php?option=com_virtuemart&view=offers&task=getOffers&page=1&format=raw',
dataType: 'json',
singleSelect: true,
colModel: [{
display: 'id',
name: 'id',
width: 100,
sortable: true,
align: 'center'
}, {
display: 'startdate',
name: 'startdate',
width: 180,
sortable: true,
align: 'center'
}, {
display: 'enddate',
name: 'enddate',
width: 180,
sortable: true,
align: 'left'
}, {
display: 'product_name',
name: 'product_name',
width: 120,
sortable: true,
align: 'left'
}, {
display: 'discount_amount €',
name: 'discount_amount',
width: 100,
sortable: true,
align: 'left'
}, {
display: 'discount_percent %',
name: 'discount_percent',
width: 120,
sortable: true,
align: 'right'
}],
searchitems: [{
display: 'startdate',
name: 'startdate',
isdefault: true
}, {
display: 'enddate',
name: 'enddate'
}, {
display: 'product_name',
name: 'product_name'
}, {
display: 'discount_amount',
name: 'discount_amount'
}, {
display: 'discount_percent',
name: 'discount_percent'
}],
sortname: "id",
sortorder: "asc",
usepager: true,
title: 'Offer',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 900,
onSubmit: addFormData,
height: 200,
buttons: [{
name: 'Testfunc1',
onpress: testfunc1
}]
});
//JUST CREATE THE PRODUCTS GRID
jQuery("#pnlProducts").flexigrid({
dataType: 'json',
singleSelect: true,
colModel: [{
display: 'id',
name: 'id',
width: 100,
sortable: true,
align: 'center'
}, {
display: 'name',
name: 'name',
width: 180,
sortable: true,
align: 'center'
}, {
display: 'price',
name: 'price',
width: 180,
sortable: true,
align: 'left'
}],
searchitems: [{
display: 'id',
name: 'id',
isdefault: true
}, {
display: 'name',
name: 'name'
}, {
display: 'price',
name: 'price'
}],
sortname: "id",
sortorder: "asc",
usepager: true,
title: 'Products',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 900,
onSubmit: addFormData,
height: 200,
buttons: [{
name: 'Testfunc2',
onpress: testfunc2
}]
});
jQuery("#LoadProducts").click(function () {
//MANUALLY FILL THE PRODUCT GRID START
//But Search,Sort,Paging wont work
/*jQuery.ajax({
type: "POST",
url: "index.php?option=com_virtuemart&view=offers&task=getProducts&page=1&rp=18&sortname=name&sortorder=asc&query=&qtype=name&format=raw",
dataType: 'json',
cache: false
}).done(function(data) {
//alert(data);
jQuery("#tblProducts").flexAddData(data);
});*/
//And this will keep the sort,search,paging working
jQuery('#tblProducts').flexOptions({
url: 'index.php?option=com_virtuemart&view=offers&task=getProducts&page=1&rp=18&sortname=name&sortorder=asc&query=&qtype=name&format=raw'
}).flexReload();
});
});
我添加一个按钮来执行对控制器的调用
<input type="button" id="LoadProducts" value="Load The product grid" >
但是我仍然不知道如何链接加载flexigrids而不会伤害排序,搜索,分页事件