Javascript 如何将数据排序重置为原始排序
我在一个现有的网站上工作,那里似乎有一个使用DataFilters jQuery插件的网站,其中数据按最低价格和最高价格排序。由于我无法控制的原因,我无法编辑原始代码,并且需要在单击时添加链接。它会将排序重置为排序之前的原始状态 谢谢你的帮助Javascript 如何将数据排序重置为原始排序,javascript,jquery,sorting,plugins,Javascript,Jquery,Sorting,Plugins,我在一个现有的网站上工作,那里似乎有一个使用DataFilters jQuery插件的网站,其中数据按最低价格和最高价格排序。由于我无法控制的原因,我无法编辑原始代码,并且需要在单击时添加链接。它会将排序重置为排序之前的原始状态 谢谢你的帮助 更新:我获得了与以下内容类似的数据过滤器初始化代码: 更新:我获得了可以更新的数据过滤器初始化代码的访问权限 $(document).ready(function() { $("#filterControls").show(); initF
更新:我获得了与以下内容类似的数据过滤器初始化代码: 更新:我获得了可以更新的数据过滤器初始化代码的访问权限
$(document).ready(function() {
$("#filterControls").show();
initFilters();
});
function initFilters() {
function freeTextSearchExtractText(element) {
return element.find('.brand').text() + " " + element.find('.model').text() + " " + element.find('.stock').text() + " " + element.find('.os').text();
}
var sortBy = [
{"heading": "Price (low-high)", "id": "cost", "direction": "1"},
{"heading": "Price (high-low)", "id": "cost", "direction": "-1"},
{"heading": "Brand (A-Z)", "id": "brand", "direction": "1"},
{"heading": "Brand (Z-A)", "id": "brand", "direction": "-1"}
]
$('#handsetList').DataFilter('init', {
"filters": [
{"id":"cost", "dataType":"currency", "filterType":"sortOnly"},
{"heading": "Brand", "id": "brand", "dataType": "default", "filterType": "checkboxes" },
{"heading": "4G readiness", "id": "tariffType", "dataType": "default", "filterType": "checkboxes", "hideSingleItem": "true" },
{"heading": "Refurbished", "id": "model", "dataType": "default", "filterType": "checkboxes", "items": ["~Refurb"] },
{"heading": "Stock status", "id": "stock", "dataType": "stock", "filterType": "checkboxes" },
{"heading": "Operating system", "id": "os", "dataType": "default", "filterType": "checkboxes"}
],
"pageSize": 9,
"useFreeTextSearch": true,
"freeTextSearchHeading": "Search phones",
"freeTextSearchExtractTextFn": freeTextSearchExtractText,
"sortingDropDown": sortBy,
"sortingDropDownHeading": "Sort phones",
"onSuccess": onSuccessFnDesktop,
"useLoadingOverlayOnFilterIfSlow": true,
"slowTimeMs": 300,
"hashNavigationEnabled": true
});
var checkVisible = setInterval(function() {
if($('.filterWrapper').length == 0 || !$('.filterWrapper').is(':visible')) return;
clearInterval(checkVisible);
merchandisedFilters();
}, 300);
}
如果无法编辑代码,则只能链接以重新加载页面。无论如何,这将是困难的,因为很可能原始订单现在就存储在这里页面重新加载是一个选项,但如果可能的话,希望避免。存储原始排序我想进一步探讨这是否是一个选项。我可以访问类似于此处内容的DataFilter初始化代码:然后向我们显示现有代码,并链接您正在使用的确切插件的文档。@Bergi问题更新为插件和代码的链接。