Tablesorter, multiple search in the same column - tablesorter

I'm trying to make a multiple search in a same column. For example if I've a colors columns and I search: "red, yell" the tablesorter should show all the red and yellow rows. I've been searching for it and I've tried to reuse the code to create my own searcher, but any result obtained. Any help would be appreciated. Thanks a lot.
I'm using Jquery 1.8.30 and jquery UI 1.9
<script src="~/Content/tablesorter-master/js/jquery.tablesorter.js" type="text/javascript"></script>
<script src="~/Content/tablesorter-master/js/jquery.tablesorter.combined.js" type="text/javascript"></script>
<script src="~/Content/tablesorter-master/js/jquery.tablesorter.widgets.js" type="text/javascript"></script>
<script src="~/Content/tablesorter-master/js/widgets/widget-columnSelector.js" type="text/javascript"></script>
<script src="~/Content/tablesorter-master/js/widgets/widget-filter.js" type="text/javascript"></script>
<script src="~/Content/tablesorter-master/js/widgets/widget-headerTitles.js" type="text/javascript"></script>
<script src="~/Content/tablesorter-master/js/widgets/widget-output.js" type="text/javascript"></script>
<script src="~/Content/tablesorter-master/js/widgets/widget-reorder.js" type="text/javascript"></script>
<script src="~/Content/jquery-ui-daterangepicker-0.4.3/jquery.comiseo.daterangepicker.js" type="text/javascript"></script>
<script src="~/Scripts/moment.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
$("#multiPicker").daterangepicker({
datepickerOptions: {
numberOfMonths: 2,
initialText: '#ViewData("SelectPeriod")'
}
});
// these default equivalents were obtained from a table of equivalents
// provided by sugar.js sorting alogrithms: http://sugarjs.com/sorting
$.tablesorter.characterEquivalents = {
'a': '\u00e1\u00e0\u00e2\u00e3\u00e4\u0105\u00e5', // áàâãäaå
'A': '\u00c1\u00c0\u00c2\u00c3\u00c4\u0104\u00c5', // ÁÀÂÃÄAÅ
'c': '\u00e7\u0107\u010d', // çcc
'C': '\u00c7\u0106\u010c', // ÇCC
'e': '\u00e9\u00e8\u00ea\u00eb\u011b\u0119', // éèêëee
'E': '\u00c9\u00c8\u00ca\u00cb\u011a\u0118', // ÉÈÊËEE
'i': '\u00ed\u00ec\u0130\u00ee\u00ef\u0131', // íìIîïi
'I': '\u00cd\u00cc\u0130\u00ce\u00cf', // ÍÌIÎÏ
'o': '\u00f3\u00f2\u00f4\u00f5\u00f6\u014d', // óòôõöo
'O': '\u00d3\u00d2\u00d4\u00d5\u00d6\u014c', // ÓÒÔÕÖO
'ss': '\u00df', // ß (s sharp)
'SS': '\u1e9e', // ? (Capital sharp s)
'u': '\u00fa\u00f9\u00fb\u00fc\u016f', // úùûüu
'U': '\u00da\u00d9\u00db\u00dc\u016e' // ÚÙÛÜU
};
// modify the above defaults as follows
$.extend($.tablesorter.characterEquivalents, {
"ae": "\u00e6", // expanding characters æ Æ
"AE": "\u00c6",
"oe": "\u00f6\u0153", // œ Œ
"OE": "\u00d6\u0152",
"d": "\u00f0", // Eth (ð Ð)
"D": "\u00d0",
"o": "\u00f3\u00f2\u00f4\u00f5", // remove ö because it's in the oe now
"O": "\u00d3\u00d2\u00d4\u00d5" // remove Ö because it's in the OE now
});
// overflow table
$('.wrapperOverflow table').tablesorter({
debug: true, //Firebug (console) needed --> /docs/example-option-debug.html
//showProcessing: true, //has bugs --> /docs/example-option-show-processing.html
sortMultiSortKey: 'altKey', //Click to sort any column header, then hold down the alt key and select a second column. Continue selecting columns as desired.
widthFixed: true,
widgets: ['filter', 'reorder', 'columnSelector'],
widgetOptions: {
sortList: [[3, 1]], //[[column, asc(0)/desc(1)]]
widgets: ['filter', 'reorder', 'resizable'],
ignoreCase: true, // if false, upper case sorts BEFORE lower case
filter_columnFilters: true,
filter_liveSearch: true,
filter_saveFilters: true,
filter_filteredRow: 'filtered',
filter_functions: true,
reorder_axis: 'xy', // 'x' or 'xy'
reorder_delay: 100,
reorder_helperClass: 'tablesorter-reorder-helper',
reorder_helperBar: 'tablesorter-reorder-helper-bar',
columnSelector_container: $('#columnSelector'),
columnSelector_columns: {},
columnSelector_saveColumns: true,
columnSelector_layout: '<label><input type="checkbox">{name}</label>',
columnSelector_name: 'data-selector-name',
columnSelector_mediaquery: true,
columnSelector_mediaqueryName: '#ViewData("Auto")' + ': ',
columnSelector_mediaqueryState: true,
columnSelector_priority: 'data-priority',
columnSelector_cssChecked: 'checked'
}
});
//http://stackoverflow.com/questions/247305/using-jquery-tablesorter-on-dynamically-modified-table
$('.wrapperOverflow table').trigger("update");
$('.wrapperOverflow table').trigger("appendCache");
//Filters style
$(".tablesorter-filter").addClass("searchStyle");
//Reset button
$('#butReset').click(function () {
var thereIsSearch = false
$(".searchStyle").each(function () {
$('input[type=search]').val('');
thereIsSearch = true
});
if (thereIsSearch == true) {
var e = jQuery.Event("keypress");
e.which = 13; //choose the one you want
e.keyCode = 13;
$('.searchStyle').trigger(e);
}
});
});
</script>

If you are using my fork of tablesorter, then the filter widget will accept "OR" searches using a vertical bar | or the word "or" surrounded by spaces or. Here is an example:
$.tablesorter.setFilters( $('table'), ['', 'Aaron|Peter' ], true );
or
$.tablesorter.setFilters( $('table'), ['', '', 'Hood or Parker' ], true );

Related

Google Linechart - No Pointsize, Tooltips?

I'm using a Linechart from Google, in which I have drawn a graph from JSON data. There are two problems I'm running into I can't seem to fix.
Even though I have 'pointSize: 6' in my options, I still can't seem to draw any kind of point, anywhere on the graph. They just don't get visible.
I can't seem to edit any tooltip. I've added a new column, and neither "dataTable.setValue(i, 2, 'test')" nor manually adding a new entry in the JSON file with "Tooltip":"Test" seems to work.
Anyone who knows what I'm doing wrong, or who has a better suggestion for perhaps a framework/api to use? I'm trying to visualise a datastory with simple code.
<html>
<head>
<style>
body{
/*overflow: hidden;*/
}
#linechart{
margin-top: 20px;
margin-left: 30px}
</style>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.1.2.min.js"></script>
<script src='js/dimple.v2.1.2.js'></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1.1', {packages: ['line']});
google.setOnLoadCallback(drawChart);
function drawChart() {
$(function() {
$.getJSON('data/priceData.json', function(data) {
var dataTable = new google.visualization.DataTable();
dataTable.addRows(1800);
dataTable.addColumn('string', 'Date');
dataTable.addColumn('number', 'Value');
//dataTable.addColumn({type: 'string', role: 'tooltip'});
dataTable.addColumn({ type: 'string', role: 'tooltip', 'p': { 'html': true} });
$.each(data, function(i, object){
dataTable.setValue(i, 0, object.DateY);
dataTable.setValue(i, 1, object.ClosePrice);
dataTable.setValue(i, 2, object.Tooltip);
//dataTable.setValue(i, 2, 'yo');
});
var options = {
colors: ['orange'],
tooltip: {isHtml: true},
chart: {
title: 'The Value of the Bitcoin',
subtitle: 'in dollars (USD)'
},
animation: {
duration: 1000,
easing: 'in',
startup: true
},
width: 1950,
height: 850,
pointSize: 6
};
var chart = new google.charts.Line(document.getElementById('linechart'));
chart.draw(dataTable, options);
});
});
};
</script>
</head>
<body>
<div id="linechart"></div>
</body>
</html>
I got this to work using google.visualization.LineChart instead of google.charts.Line.
It gives me both points and tooltips, see here:
Instead of using
google.load('visualization', '1.1', {packages: ['line']});
Just try including
<script type="text/javascript"
src="https://www.google.com/jsapi?autoload={
'modules':[{
'name':'visualization',
'version':'1',
'packages':['corechart']
}]
}"></script>
Then instead of:
var chart = new google.charts.Line(document.getElementById('linechart'));
Just try using:
var chart = new google.visualization.LineChart(document.getElementById('linechart'));
That ought to do it. Let me know if you have other problems.

How to combine these 2 small tablesorter scripts

I have a jquery tablesorter script, and I am trying to add these two functions together. It seems like it would be simple, though unfortunately I have very little knowledge with javascript.
It will only work when I have one or the other in the , not like i have it below.
<script type="text/javascript">
$(document).ready(function(){
$(function() {
$("table").tablesorter({ sortList:[[0,0]]
}); }); });
$(document).ready(function(){
$("table").tablesorter({
textExtraction:function(s){
if($(s).find('img').length == 0) return $(s).text();
return $(s).find('img').attr('alt');
}
});
});
</script>
Try to do:
<script type="text/javascript">
$(document).ready(function () {
$("table").tablesorter({
sortList: [
[0, 0]
],
textExtraction: function (s) {
if ($(s).find('img').length == 0) return $(s).text();
return $(s).find('img').attr('alt');
}
});
});
</script>

Table not building

So as I'm not knowledgeable about jQuery and JavaScript I'm following the simpler method of using an array to build a table with Tablesorter. However, this is not working at all. In fact, even if I use the example provided (here: http://mottie.github.io/tablesorter/docs/example-widget-build-table.html) there is no result just a blank webpage. Here's my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Testing Tablesorter (fork)</title>
<!-- load tableSorter theme -->
<link href="./includes/tablesorter-master/css/theme.default.css" rel="stylesheet">
<!-- load jQuery and tableSorter scripts -->
<script type="text/javascript" src="./includes/jquery-2.1.0.js"></script>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.js"></script> -->
<script type="text/javascript" src="./includes/tablesorter-master/js/jquery.tablesorter.js"></script>
<!-- load tableSorter widgets -->
<script type="text/javascript" src="./includes/tablesorter-master/js/jquery.tablesorter.widgets.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// Call the PHP script that grabs all data from DB
$.getJSON('./get_data.php',function(data){
//alert(data.length);
var dataArr = new Array();
for (x = 0; x < data.length; x++)
{
dataArr[x] = data[x];
//console.log(dataArr[$x]);
}
applyTable(dataArr);
});
});
function applyTable(arrayIn)
{
//alert(arrayIn[0]);
$('#topdiv').tablesorter({
theme : 'default',
//widgets : ['zebra','columns'],
debug : true,
widgetOptions : {
build_source : arrayIn,
build_headers : {
rows : 1,
classes : [],
text : [],
widths : [ '15%', '15%', '30%', '15%', '40%', '30%', '30%', '30%', '30%', '30%' ]
}
}
});
$("#topdiv").trigger("updateAll");
}
</script>
</head>
<body>
<div id="topdiv"></div>
</body>
</html>
Any ideas? Mottie, where are you.
EDIT: Chrome reports no JavsScript errors. Though the console (since I specified "debug: true") gives:
stopping initialization! No table, thead, tbody or tablesorter has already been initialized
I also know that the PHP script is working fine.
EDIT, PHP CODE (excerpt):
$headersArr = array('ID', 'Col 2', 'Col 3',
'Col 4', 'Col 5', 'Col 6',
'Col 7', 'Col 8', 'Col 9', 'Col 10');
$allArr = array();
array_push($allArr, $headersArr);
while($row = mysql_fetch_object($rs))
{
$newRow = array($row->id, $row->col_B, $row->col_C,
$row->col_D, $row->col_E,
$row->col_F, $row->col_G,
$row->col_H, $row->col_I,
$row->col_J);
array_push($allArr, $newRow);
}
echo json_encode($jobsArr);
The following image is the JavaScript output in the Chrome console (I have not updated the code above to keep it from getting to big, but I simply repacked the array passed to applyTable() and outputted both arrays to the console). Which one of these arrays should be for use with Tablesorter?
From looking at the code, it looks like the array is just one long array.
dataArr = [ 'r0c0', 'r0c1', 'r0c2', 'r1c0', 'r1c1', 'r1c2', ... ];
It needs to be an array of row arrays:
dataArr = [
['r0c0', 'r0c1', 'r0c2'],
['r1c0', 'r1c1', 'r1c2'],
...
];
so make two loops (demo):
$(function () {
// Declare the array holding the data
var dataArr = [];
// Call the PHP script that grabs all data from DB
$.getJSON('./get_data.php', function (data) {
var i, j, row,
// you need to know how many columns
columns = 3,
// calculate how many rows
rows = Math.ceil(data.length / columns);
for (i = 0; i < rows; i++) {
// clear row array
row = [];
for (j = 0; j < columns; j++) {
row.push(data[i * columns + j]);
}
dataArr.push(row);
}
applyTable(dataArr);
});
});
function applyTable(arrayIn) {
$('#topdiv').tablesorter({
theme: 'default',
//widgets : ['zebra','columns'],
widgetOptions: {
build_source: arrayIn,
build_headers: {
rows: 1,
widths: ['33%', '33%', '33%']
}
}
});
}
And don't trigger an "updateAll" because the table was just built.
The error you mentioned is still showing up, it looks like an bug, but it's just an unintentional message, nothing else.
The table was not building due to missing the line in the HTML header:
<script type="text/javascript" src="./includes/tablesorter-master/js/widgets/widget-build-table.js"></script>
The PHP script is absolutely fine. The only JavaScript req'd is:
$(document).ready(function(){
$.getJSON('./get_data.php',function(data){
applyTable(data);
});
});
function applyTable(arrayIn){
$('#topdiv').tablesorter({
theme: 'default',
//widgets : ['zebra','columns'],
debug: true,
widgetOptions: {
build_source: arrayIn,
build_headers: {
rows: 1
}
}
});

JQuery autocomplete ui.item.value only returning one word - MVC3

:I have the following in one of my partial views:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#ProductName").autocomplete({
source: "Products",
minLength: 2,
select: function (event, ui) {
$("#newInvoiceLineForm").load("/Invoices/Product?name=" + ui.item.value);
}
});
});
</script>
And the autocomplete works fine and displays all the items returned but on select event I get a ui.item.value with just the first word of the two word item. For example I have "New Product" selected from the autocomplete and it results in the:
/Invoices/Product?name=New call.
Anyone had this situation before?
Thank you
This is the code that works with encodeURI:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#ProductName").autocomplete({
source: "Products",
minLength: 2,
select: function (event, ui) {
$("#newInvoiceLineForm").load(encodeURI("/Invoices/Product?name=" + ui.item.value));
}
});
});
</script>
You need to URL encode your string. Spaces in their raw form aren't acceptable to querystrings.

jqGrid: No such method: restoreRow

I am having an issue working with jaGrid and ASP.NET MVC 2. Everything is working, but when I select a row I get this error on FireBug: uncaught exception: jqGrid - No such method: restoreRow.
Debugin Js I realize that error happend here:
onSelectRow: function(id) {
if (id && id !== lastsel) {
jQuery('#list').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('editRow', id, true);
lastsel = id;
}
I think, the problem is the jqGrid libraries include (or the include order). This is my Index.aspx page.
<%--CSS Files--%>
<link href="/Content/jquery-ui-1.8.7.css" rel="stylesheet" type="text/css" />
<link href="/Content/ui.jqgrid.css" rel="stylesheet" type="text/css" />
<link href="/Content/ui.multiselect.css" rel="stylesheet" type="text/css" />
<%--jQuery Library--%>
<script type="text/javascript" src="../../Scripts/jquery-1.4.4.min.js"></script>
<%--Must load language tag BEFORE script tag--%>
<script type="text/javascript" src="../../Scripts/grid.locale-es.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="../../Scripts/grid.jqueryui.js"></script>
<script type="text/javascript" src="../../Scripts/grid.base.js"></script>
<script type="text/javascript" src="../../Scripts/grid.common.js"></script>
<script type="text/javascript" src="../../Scripts/grid.formedit.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.fmatter.js"></script>
<script type="text/javascript" src="../../Scripts/grid.custom.js"></script>
<script type="text/javascript" src="../../Scripts/jqDnR.js"></script>
<script type="text/javascript" src="../../Scripts/jqModal.js"></script>
<script type="text/javascript" src="../../Scripts/grid.import.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table id="tableAccidentes" border=0>
<tr>
<td><img alt="" src="../../images/icono_victima.png" /></td>
<td><h2>Accidentes Registrados</h2></td>
</tr>
</table>
<script type="text/javascript">
var lastsel;
var Plantas = ['Pablo Podesta', 'Pilar', 'Tigre', 'Otra'];
jQuery(document).ready(function() {
jQuery("#list").jqGrid({
url: '/Accidentes/ListarAccidentes',
datatype: "json",
colNames: ['Fecha', 'Detalle', 'Accidentado', 'Planta'],
colModel: [
{ name:'Fecha', index:'Fecha', width:150, align:'left',
editable:true },
{ name:'Detalle', index:'Detalle', width:150, align:'left',
editable:true },
{ name:'Accidentado', index:'Accidentado', width:200,
align:'left', editable:true },
{ name:'planta', index:'planta', width:150, align:'left',
editable:true, edittype:"select",
editoptions: { value:Plantas} }
],
onSelectRow: function(id) {
if (id && id !== lastsel) {
jQuery('#list').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('editRow', id, true);
lastsel = id;
}
},
editurl: "/Accidentes/GridSave",
edit: {
addCaption: "Agregar Accidente",
editCaption: "Editar Accidente",
bSubmit: "Guardar",
bCancel: "Cancelar",
bClose: "Cerrar",
saveData: "Se modifico el registro! ¿guardar los cambios?",
bYes: "Si",
bNo: "No",
bExit: "Cancelar"
},
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'Accidente'
}).navGrid('#pager', { edit: true, add: true, search: false, del: false },
{ closeAfterAdd: true, closeAfterEdit: true });
// add custom button to export the data to excel
jQuery("#list").jqGrid('navButtonAdd','#pager',{
caption:"",
onClickButton : function () {
jQuery("#list").jqGrid('excelExport',
{ url: '/Accidentes/ExportarAccidentes' });
}
});
});
</script>
<%-- HTML Required--%>
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
Please, can someone help me?
The restoreRow and editRow methods, which you use, are defined in the grid.inlinedit.js file and are the part of the inline editing module (see more in the jqGrid documentation). Moreover you should remove the file jquery.jqGrid.min.js to avoid having definitions of the same functions twice. Because the method restoreRow was not defined in the jquery.jqGrid.min.js which you use you use probably wrong downloaded jqGrid version. You should download the jqGrid one more time and be sure that you check "Inline Editing" module. If you open jquery.jqGrid.min.js file in the text editor you will see in the comment at the begining of the file all modules which was the part of the download.
Some additional small remarks: in the documentation is described which parameters of the colModel are default. For example, width:150 and align:'left' have defaout values, so you can remove there from the column definition.
The value property for "select" type of the editoptions which you use is wrong. The Plantas should be defined as
var Plantas = { 'Pablo Podesta':'Pablo Podesta', Pilar:'Pilar',
Tigre:'Tigre', Otra:'Otra'};
or as
var Plantas = 'Pablo Podesta:Pablo Podesta;Pilar:Pilar;Tigre:Tigre;Otra:Otra';
See the documentation for details.
The parameter imgpath is deprecated and should be removed. Class "scroll" is also deprecated and the HTML fragment for the jqGrid can be reduced to
<table id="list"></table>
<div id="pager"></div>
See an example here.
The parameter edit is not exist in the jqGrid it is the parameter of editGridRow from the form editing. You can define it as the part of navGrid parameters prmEdit and prmAdd. Currently you use only prmEdit. Probably the usage of grid.locale-XX.js from the i18n directory will make the usage of edit parameter unneeded.

Resources