Tablesorter 即时设置输出小部件选项
Tablesorter Set output widget options on the fly
我正在使用 Mottie 的 table分拣叉。我对 javascript 不是很有经验,但到目前为止我已经完成了所有工作。这是问题所在:
现在我想在我的 table 上方有两个按钮,以允许下载所有行或只下载选定的行。
为此,我有以下 javascript 部分有效的代码。我只需要让它工作以下载所有(!)行。
我做错了什么?
这里是输出全部的部分:
$('.downloadall').click(function(){
var $table = $('.tablesorter');
wo = $table[0].config.widgetOptions,
saved = $table.find('.output-filter-all :checked').attr('class');
wo.output_includeHTML = false;
wo.output_delivery = 'p';
// d = download p = page
wo.output_saveRows ='a';
// a = all f=filtered
$table.trigger('outputTable');
return false;
});
这非常有效,包括所有其他输出选项的设置。
下面的代码做完全相同的事情,但我当然只想要选定的行。
$('.downloadselected').click(function(){
var $table = $('.tablesorter');
wo = $table[0].config.widgetOptions,
saved = $table.find('.output-filter-all :checked').attr('class');
wo.output_includeHTML = false;
wo.output_delivery = 'p';
// d = download p = page
wo.output_saveRows = saved;
// a = all f=filtered
$table.trigger('outputTable');
return false;
});
我尝试了各种方法,但都没有成功。
因为我不知道 table HTML 会带来什么。我不知道 saved
变量最终会变成什么,但它似乎缺少制作 jQuery select 或 class 名称的前导句点。
wo.output_saveRows = '.' + saved;
无论如何,这让我想到目前你不能 select 基于其内容的行,所以我更新了 saveRows
选项以现在接受 filter callback function which as of this writing is currently only available in the master branch,并且可以按如下方式使用:
$('.downloadselected').click(function(){
var $table = $('.tablesorter'),
wo = $table[0].config.widgetOptions
wo.output_includeHTML = false;
wo.output_delivery = 'p';
wo.output_saveRows = function(){
// include row only if it has a checked checkbox
return $(this).find('input[type="checkbox"]:checked').length > 0;
};
$table.trigger('outputTable');
return false;
});
好吧,我只是忽略了 class 名称“.saved”当然不正确。最后,Mottie 为我指明了正确的方向。这是我最初问题的解决方案,只需使用正确的 class 名称 .checked 一切都会按预期工作。:
$('.downloadselected').click(function(){
var $this =$('#table');
var $table = $('.tablesorter');
wo = $table[0].config.widgetOptions,
wo.output_includeHTML = false;
wo.output_delivery = 'p';
// d = download p = page
//saved = '.checked';
// a = all f=filtered
wo.output_saveRows = '.checked';
$table.trigger('outputTable');
return false;
});
它
我正在使用 Mottie 的 table分拣叉。我对 javascript 不是很有经验,但到目前为止我已经完成了所有工作。这是问题所在: 现在我想在我的 table 上方有两个按钮,以允许下载所有行或只下载选定的行。
为此,我有以下 javascript 部分有效的代码。我只需要让它工作以下载所有(!)行。
我做错了什么?
这里是输出全部的部分:
$('.downloadall').click(function(){
var $table = $('.tablesorter');
wo = $table[0].config.widgetOptions,
saved = $table.find('.output-filter-all :checked').attr('class');
wo.output_includeHTML = false;
wo.output_delivery = 'p';
// d = download p = page
wo.output_saveRows ='a';
// a = all f=filtered
$table.trigger('outputTable');
return false;
});
这非常有效,包括所有其他输出选项的设置。 下面的代码做完全相同的事情,但我当然只想要选定的行。
$('.downloadselected').click(function(){
var $table = $('.tablesorter');
wo = $table[0].config.widgetOptions,
saved = $table.find('.output-filter-all :checked').attr('class');
wo.output_includeHTML = false;
wo.output_delivery = 'p';
// d = download p = page
wo.output_saveRows = saved;
// a = all f=filtered
$table.trigger('outputTable');
return false;
});
我尝试了各种方法,但都没有成功。
因为我不知道 table HTML 会带来什么。我不知道 saved
变量最终会变成什么,但它似乎缺少制作 jQuery select 或 class 名称的前导句点。
wo.output_saveRows = '.' + saved;
无论如何,这让我想到目前你不能 select 基于其内容的行,所以我更新了 saveRows
选项以现在接受 filter callback function which as of this writing is currently only available in the master branch,并且可以按如下方式使用:
$('.downloadselected').click(function(){
var $table = $('.tablesorter'),
wo = $table[0].config.widgetOptions
wo.output_includeHTML = false;
wo.output_delivery = 'p';
wo.output_saveRows = function(){
// include row only if it has a checked checkbox
return $(this).find('input[type="checkbox"]:checked').length > 0;
};
$table.trigger('outputTable');
return false;
});
好吧,我只是忽略了 class 名称“.saved”当然不正确。最后,Mottie 为我指明了正确的方向。这是我最初问题的解决方案,只需使用正确的 class 名称 .checked 一切都会按预期工作。:
$('.downloadselected').click(function(){
var $this =$('#table');
var $table = $('.tablesorter');
wo = $table[0].config.widgetOptions,
wo.output_includeHTML = false;
wo.output_delivery = 'p';
// d = download p = page
//saved = '.checked';
// a = all f=filtered
wo.output_saveRows = '.checked';
$table.trigger('outputTable');
return false;
});
它