JQuery DataTable - Search for exact match - javascript

I have looked at several other responses and tried them all but nothing works. I have the following in my table:
Date Severity
2016-04-24 Not Critical
2016-04-24 Critical [what I need returned]
2017-01-09 Not Critical
2017-09-13 Critical
I am trying to search for all rows where severity is Critical (value) for 2016 (year). So far I have:
table.search( year + " " + value ).draw();
This returns both rows for 2016. How can I get it to return just the row that I need?

You may need to enable and use regular expressions with search() and column().search() API methods.
Since you need to search two columns simultaneously, it may be better to combine two calls to column().search().
For example:
table
.column(0).search('2016')
.column(1).search('^Critical$', true, false)
.draw();
where 0 and 1 are indexes of your date and severity columns.
See this example for code and demonstration.

Related

Auto-increment dates in two cells if date has passed

Overview:
I'm not a programmer but I managed to get some serious coding into a Gsheets to track my teams project, so we have multiple-variable dropdown menus and integration with google calendar to track projects development and all that.
Why I'm at stackoverflow:
I kind of lack the knowledge to start the code from the scratch, I usually find spare parts of code through forums on the internet and clue them together and it usually works surprisingly well, but this time I couldn't find much informtation.
What I need:
I have 5 cells, and we can put as below,
Date start - Date end - date code* - number** - Priority***
*script to add the date range to gcalendar
** & *** The number is an array that's based on the word written on the priority cell, for example: If priority is written Weekly them
the number colunm will show 7 on the cell to the left and them it
goes. (monthly = 30 and blablabla...)
So I'd like to know if someone could give a hand with a script that would work (at least in my head) as following:
If I set the priority to weekly, it will show 7 on the number colunm and them, every time the "Date end" has passed, it will automatically add 7 days to the "Date start" and "Date end" again.
That way I could keep the projects on a loop where I'll be able to track them constatly.
Thanks in advance for any insights provided,
ps: I've seen some posts about this on sql, but I have no idea also on how to take advantage of the proposals that were presented there.
Edit:
Spreadsheet picture
eDIT2:
Spreadsheet with a increment colunm
Pertinent to the data set and description, you probably do not need any VBA as the increment could be achieved by adding +1 to the reference pointing to previous cell. For example, assuming cell A1 is formatted as Date, enter in cell B1: =A1+1 , then in cell C1: =B1+1 and so on. The result should be as shown below
A B C
9/1/2017 9/2/2017 9/3/2017
It could be further extended with simple logic allowing do display incremented value only if the previous cell is not empty, like : =IF(A1,A1+1,"")
In your case, it could be cell F1 containing =IF(E1,E1+1,"").
FYI, the underlying value of Date is just an Integer value (Time is represented as decimal part), so the arithmetic operations could be applied.
More generic solution would be based on the Excel DATE() Worksheet formula as shown in sample shown below (adding 1 mo. to the date entered in cell A1):
=DATE(YEAR(A1), MONTH(A1)+1, DAY(A1))
In order to implement additional logic, you may consider using Excel Worksheet IF() statement like for example, cell B1 containing:
=A1+IF(C1="week",7,1)
A B C
9/1/2017 9/8/2017 week
so based on the IF() condition it will add either 7 days if C1 contains the word "week" or 1 day otherwise. It could be further extended with nested IF().
Hope this will help.

Best way to search a row in google spreadsheet

So, been looking at search functions in google spreadsheet, and find it difficult to figure out a smooth way to find which column on row one contain a specific value.
To explain a bit more, its a simple allocation spreadsheet, basically who works as what on which project for how long, and as we have a number of different pipelines, I wanted the pipelines separated. So I created a sheet for each, set up the first five collumns so contain all kind of useful info (like resource, project, project role, chargeable, client) then the rest of the collumns represents weeks, so each collumn have the date of the Monday, and all eight sheets have the same setup, so column 6 to 28 contains the date of the following Monday, allowing me to predict resource allocation a total of 22 weeks or thereabouts.
The next step is to create a report (sheet 1) which tells me by resource how busy they are, either as summary or as detailed+summary, and put some colour in if anyone is allocated to many or to few days in a specific week.
I also wanted to view to allow me to specify a date, easy enough, two drop down menus. First is the list of dates row one sheet two, second one is the same list, so the user can in specify 27/01/2014 - 03/04/2014 from the drop down list.
Now comes my issue, I want to retrieve the numerical value of the columns matching the date, so if the start date is in column F I want a variable with 6 in. And end date is in M thats 14.
Anyone have any good suggestions how this can be done?
Tried reading the row and searching it as an array, did not work particularly well
var vcSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Office");
var range = vcSheet.getRange(1,1,1,28);
var dates = range.getValue();
var strCol = dates.indexOf(dtStart);
var stpCol = dates.indexOf('Task');
Browser.msgBox('Found start col on ' + strCol + ' end col on ' + stpCol);
Have you tried .getValues(), as opposed to .getValue()? Maybe something like;
var dates=range.getValues();
for (i in dates[0]) {
if (dates[0][i].indexOf(dtStart)>-1) { some stuff }
}

Fixing Numerical Sort with Table Sorter

I am having a strange issue with a Table Sorter Plugin (http://tablesorter.com/docs/)
The numerical sort seems to not work when sorting with $'s and ,'s. Here is a screenshot of what it is doing. Does anybody know how to fix this?
Here is my table sorting code on the page with the table
$(document).ready(function(load)
{
$("#myTable").tablesorter({
sortList: [[1,1]] // etc.
});
}
);
If it doesn't detect the type automatically (as it should), you can force it. Here is an example from the comments in the source code:
$('table').tablesorter({ headers: { 0: {sorter:"integer"}, 1: {sorter:"currency"} } });
In this case, it looks like the second column should be sorted as currency.
my experienced eyes saw that your list is mis-sorted if there is a comma "," as decimal character separator but the js expect it to have locale that uses "." as separator
you could easily replace the commas with dots just google for "jquery replace"
but i would rather introduce you n numeral.js, wich has handy functions http://numeraljs.com/
or even better would be to output the correct data format from serverside
btw with numeral you could simply do
number = numeral(number).format('$0.0.00');

TableSorter doesn't recognize numbers

I have these two examples, which both use the same code but different sources of tablesorter. However one of them works as the other one doesn't.
$("table").tablesorter();
http://jsfiddle.net/lightheaded/x78cd/ (doesn't work)
http://jsfiddle.net/lightheaded/RYL54/ (works)
It should first sort by percent and then by users. However it doesn't recognize the second number to be a number. I have a similar situation on my site. What could be the issue? I'm using 2.14.4 min on my site as well.
Upgrade to a more recent version of table sorter. Recent version seems to parse out tokens from strings such as 99% coverage (12.08 million users) and 99% coverage (10.2 million users) and compare them one by one so strings that contain more than one number still sort out as expected (we have 10 compared with 12 in the above example).
OR: you can create a custom parser that normalizes the percentage and users; and use it:
$.tablesorter.addParser({
id: 'percentThenUsers',
is: function (s) {
return false;
},
format: function (s) {
// "99% coverage (12.08 million users)" gets converted to
// "1099 1012.08" which can then be sorted as text
var m = s.replace(/[^\d\.]/g, " ").replace(/ +/g, " ").split(" ");
return (+m[0] + 1000) + " " + (+m[1] + 1000);
},
type: 'text'
});
$(function () {
$("table").tablesorter({
debug: true,
headers: {
0: { sorter: 'percentThenUsers' }
}
});
});
Demo here
Tablesorter attempts to detect the content of table cells automatically. In this case it is finding text and not percentage or digit values.
The first demo is using the original tablesorter which doesn't use alphanumeric sorting, so it can only sort text blocks. Check out this updated demo where a row with this data is added:
<tr><td>10% coverage (1.0 million users)</td></tr>
The 10% is placed above 100% in ascending sorts - not what you would expect.
The second demo is using an updated version of tablesorter which does use alphanumeric sorting. It splits the text into blocks and is able to sort the content as you would expect. Here is an updated demo with the above row included.
If you "need" to use the original tablesorter, then use the parser provided by #SalmanA.

Javascript fuzzy filter for text-based ranges, need a regex perhaps?

I have a database of a few hundred schools (more added constantly) where one field has a verbose description of the grade levels it serves. Examples: 'K-6', '9-12', 'PK-4', 'K-3 and 6-8', 'grades 4-8'
I am rendering this data in an HTML table and using a 'select' drop-down to filter by specific grade. I would like to have the 'options' for this drop-down be single grades, such as K, 1st, 2nd, 3rd, etc. But I need a regex or some means (via javascript) to compare to this field to be sure the user-selected grade falls within the range so I can highlight the 'table' row.
BTW, I am also using the jquery library.
Try this to search the description for ranges:
/(PK|[K1-9])(\s*(-|to)\s*)(PK|[K1-9])/i
Test it.
Of course you may want to modify it and add some extra logic. It's just a starting point.
I hope this helps you,
Alin

Categories

Resources