提交 7b3b040b 编写于 作者: C Catouse

* datatable support storage option and updated document.

上级 6e822105
......@@ -151,6 +151,16 @@ $('table.datatable').datatable({checkable: true, sortable: true});
<p>仅在<code>checkable</code>选项为<code>true</code>时生效</p>
</td>
</tr>
<tr>
<td><code>storage</code></td>
<td>
<ul>
<li><code>false</code></li>
<li><code>true</code> (默认)</li>
</ul>
</td>
<td>是否启用本地存储来增强用户体验。启用该选项之后,表格排序状态及选中的行在用户刷新页面之后仍然会还原为之前的扎状态。</td>
</tr>
<tr>
<td><code>sortable</code></td>
<td>
......
......@@ -53,6 +53,9 @@
// Sort options
sortable: false, // enable sorter
// storage
storage: true, // enable storage
// fixed header of columns
fixedHeader: true, // fixed header
fixedHeaderOffset: 0, // set top offset of header when fixed
......@@ -585,7 +588,7 @@
$datatable.toggleClass('scrolled-in', barLeft > 2)
.toggleClass('scrolled-out', barLeft < flexWidth - scrollWidth - 2);
store.pageSet(scrollOffsetStoreName, barLeft);
if(options.storage) store.pageSet(scrollOffsetStoreName, barLeft);
};
var resizeScrollbar = function()
{
......@@ -610,7 +613,7 @@
};
// $scrollbar.resize(resizeScrollbar); // todo: unuseful?
$flexArea.resize(resizeScrollbar);
resizeScrollbar();
if(options.storage) resizeScrollbar();
var dragOptions = {
move: false,
......@@ -667,7 +670,7 @@
});
$headSpans.find('.check-all').toggleClass('checked', checkedStatus.checkedAll);
store.pageSet(checkedStatusStoreName, checkedStatus);
if(options.storage) store.pageSet(checkedStatusStoreName, checkedStatus);
that.callEvent('checksChanged',
{
......@@ -695,25 +698,28 @@
syncChecks();
});
var checkedStatus = store.pageGet(checkedStatusStoreName);
if (checkedStatus)
if(options.storage)
{
$headSpans.find('.check-all').toggleClass('checked', checkedStatus.checkedAll);
if (checkedStatus.checkedAll)
var checkedStatus = store.pageGet(checkedStatusStoreName);
if (checkedStatus)
{
$rows.addClass(checkedClass);
}
else
{
$rows.removeClass(checkedClass);
$.each(checkedStatus.checks, function(index, ele)
$headSpans.find('.check-all').toggleClass('checked', checkedStatus.checkedAll);
if (checkedStatus.checkedAll)
{
$rows.filter('[data-id="' + ele + '"]').addClass(checkedClass);
});
}
if (checkedStatus.checks.length)
{
syncChecks();
$rows.addClass(checkedClass);
}
else
{
$rows.removeClass(checkedClass);
$.each(checkedStatus.checks, function(index, ele)
{
$rows.filter('[data-id="' + ele + '"]').addClass(checkedClass);
});
}
if (checkedStatus.checks.length)
{
syncChecks();
}
}
}
}
......@@ -764,9 +770,10 @@
// Sort table
DataTable.prototype.sortTable = function($th)
{
var store = window.store;
var store = window.store,
options = this.options;
var sorterStoreName = this.id + '_datatableSorter';
var sorter = store.pageGet(sorterStoreName);
var sorter = options.storage ? store.pageGet(sorterStoreName) : null;
if (!$th)
{
......@@ -872,7 +879,7 @@
};
// save sort with local storage
store.pageSet(sorterStoreName, sorter);
if(options.storage) store.pageSet(sorterStoreName, sorter);
this.callEvent('sort',
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册