Slickgrid sorting when using DataView and expand/collapse - slickgrid

I've been doing a LOT of googling, but couldn't find a way to implement this. Sorry if I missed it in my searching.
I used Example 4 adding tree functionality as a template, but I've been unable to implement column sorting while tree functionality is active.
Everything I've tried winds up in an infinite loop in the rendered version of my inline filter due to the IDs no longer being in order.
Has anyone been able to implement sorting with tree functionality or have any pointers how it can be accomplished? Is there a way to sort the parent rows and leave the parents and children together?
My filter is basically the same as the one in the example with some minor tweaks to the search.
It gets stuck looping the item.parent if since the parents and children are no longer sequential. Now all rows have children.
if (item.parent != null) {
var parent = oppLineGridData[item.parent];
while (parent) {
if (parent._collapsed) {
return false;
}
parent = oppLineGridData[parent.parent];
}
}
Full function:
function openFilter(item) {
if (specificColumn != null) {
if (searchString != "" && item[specificColumn].toLowerCase().indexOf(searchString) == -1) {
return false;
}
} else {
if (searchString != ""
&& item["accountName"].toLowerCase().indexOf(searchString) == -1
&& item["solution"].toString().toLowerCase().indexOf(searchString) == -1
&& item["Adjusted_Commitment__c"].toLowerCase().indexOf(searchString) == -1
&& item["Deal_Registration_ID__c"].toLowerCase().indexOf(searchString) == -1
&& item["lineItemValue"].toString().toLowerCase().indexOf(searchString) == -1
&& item["oppotunityName"].toLowerCase().indexOf(searchString) == -1
&& item["closeDate"].toLowerCase().indexOf(searchString) == -1
&& item["productName"].toLowerCase().indexOf(searchString) == -1
&& item["stageName"].toLowerCase().indexOf(searchString) == -1
&& item["ownerName"].toLowerCase().indexOf(searchString) == -1
&& item["accountManagerList"].toLowerCase().indexOf(searchString) == -1
&& item["accountManagerMgr2"].toLowerCase().indexOf(searchString) == -1
&& item["ProServicesEngagement"].toLowerCase().indexOf(searchString) == -1
&& item["proServicesEngagementAll"].toLowerCase().indexOf(searchString) == -1
&& item["productType"].toLowerCase().indexOf(searchString) == -1
&& item["commissionableEMName"].toLowerCase().indexOf(searchString) == -1
&& item["lastUpdated"].toLowerCase().indexOf(searchString) == -1
&& item["updatedBy"].toLowerCase().indexOf(searchString) == -1) {
return false;
}
}
if (item.parent != null) {
var parent = oppLineGridData[item.parent];
while (parent) {
if (parent._collapsed) {
return false;
}
parent = oppLineGridData[parent.parent];
}
}
return true;
}

The only answer is to disable the inlining of filters. In other words, the option inlineFilters should be set to false.
I just suffered from the same issue and I tell you this from the experience. The inlining of filters for SlickGrid won't handle complex code.
Even a for with an if inside or a inner loop was enough for it to go into infinite loop for me.

Related

search fails with maxid (ulong.max) and sinceid set, but separately it works

the following query works ok if you comment out either the SinceID or the MaxID clause, but when both are included a "bad url" exception is generated.
var maxId = ulong.MaxValue;
var sinceId = (ulong)341350918903701507;
var searchResult =
(
from search in ctx.Search
where search.Type == SearchType.Search &&
search.ResultType == ResultType.Mixed &&
search.Query == "red wedding" &&
search.SinceID == sinceId &&
search.MaxID == maxId &&
search.IncludeEntities == false &&
search.Count == 200
select search).SingleOrDefault();
If you look at the query result in Fiddler, you'll see that the response is:
{"errors":[{"code":195,"message":"Missing or invalid url parameter"}]}
I can't respond to why Twitter wouldn't accept the query with both SinceID and MaxID. However, the query is formed correctly and there isn't any documentation describing constraints on the relationship between these two parameters for this particular scenario. The purpose of the MaxID is to be the id of the highest tweet to return on the next query. Both MaxID and SinceID are intended to help you page through data. I wrote a blog post on how to do this:
Working with Timelines with LINQ to Twitter
I seem to have the same problem as you are, so the only solution I have was to do it manually, so first I retrieved the the first list setting the sinceId value to the one I have like this:
var searchResult =
(
from search in TwitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == query &&
search.Count == pageSize &&
search.IncludeEntities == true &&
search.ResultType == ResultType.Recent &&
search.SinceID == sinceId
select search
).SingleOrDefault<Search>();
resultList = searchResult.Statuses;
Then I have to search for other tweets (the case when new tweets count is more the pageSize) so I had a while loop like this:
ulong minId = ulong.Parse(resultList.Last<Status>().StatusID) - 1;
List<Status> newList = new List<Status>();
while (minId > sinceId)
{
resultList.AddRange(newList);
searchResult =
(
from search in TwitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == query &&
search.Count == pageSize &&
search.IncludeEntities == true &&
search.ResultType == ResultType.Recent &&
search.MaxID == minId &&
search.SinceID == sinceId
select search
).SingleOrDefault<Search>();
newList = searchResult.Statuses;
if (newList.Count == 0)
break;
minId = ulong.Parse(newList.Last<Status>().StatusID) - 1;
}
Now for some reason here you can use both sinceId and maxId.
Just in case anyone else comes across this, I encountered this issue when the MaxId was an invalid Tweet Id.
I started off using zero but ulong.MaxValue has the same issue. Switch it out with a valid value and it works fine. If you're not using SinceId as well it seems to work fine.
I used to get same error "Missing or invalid url parameter", but as per Joe Mayo's solution, I have additionally added if(sinceID < maxID) condition before do while loop, because the query throws above error whenever maxID is less than sinceID, I think which is incorrect.
if (sinceID < maxID)
{
do
{
// now add sinceID and maxID
searchResponse =
await
(from search in twitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == "from:#" + twitterAccountToDisplay + " -retweets" &&
search.Count == count &&
search.SinceID == sinceID &&
search.MaxID == maxID
select search)
.SingleOrDefaultAsync();
if (searchResponse == null)
break;
if (searchResponse.Count > 0 && searchResponse.Statuses.Count > 0)
{
newStatuses = searchResponse.Statuses;
// first tweet processed on current query
maxID = newStatuses.Min(status => status.StatusID) - 1;
statusList.AddRange(newStatuses);
lastStatusCount = newStatuses.Count;
}
if (searchResponse.Count > 0 && searchResponse.Statuses.Count == 0)
{
lastStatusCount = 0;
}
}
while (lastStatusCount != 0 && statusList.Count < maxStatuses);
//(searchResponse.Count != 0 && statusList.Count < 30);
}

How to simplify a simple loop in Javascript?

I am now trying it out for a while and get it perfect. I am trying to simplify this for loop I created and make it actually work, without any arrays and only the most basic of basic JavaScript.
for (var x=0;x<=1;x++) {
if (secondInput == luckyNumber || secondInput == luckyNumber2 || secondInput == luckyNumber3) {
if (thirdInput == luckyNumber || thirdInput == luckyNumber2 || thirdInput == luckyNumber3) {
if (firstInput == luckyNumber || firstInput == luckyNumber2 || firstInput == luckyNumber3) {
while (firstInput !== secondInput){
while(firstInput !== thirdInput){while(secondInput !== thirdInput) {
alert('Congratulations! You got all 3 numbers correct. You\'ve won £1,000!');
}
}
}
}
}
}
Does this code make sense or am I doing something wrong? I've got the feeling that I can even leave the loop out, but it is the only way how I think it is correct.
Write a function that takes the input, compares it to the lucky numbers and returns a boolean with the result.
Call that function in your if clauses.
I don't quite understand what you are trying to do with the while loops.
You could try using this idea to help:
[1, 3, 2].sort()
(store your questions and answers in arrays, and sort both then compare. Of course, checking javascript arrays for equality is a fun new project :) )
Here you go. You said you wanted it simplified.
for (var x = 0; 1 >= x; x++) {
if (!(secondInput != luckyNumber && secondInput != luckyNumber2 && secondInput != luckyNumber3 || thirdInput != luckyNumber && thirdInput != luckyNumber2 && thirdInput != luckyNumber3 || firstInput != luckyNumber && firstInput != luckyNumber2 && firstInput != luckyNumber3)) {
while (firstInput !== secondInput) {
while (firstInput !== thirdInput) {
while (secondInput !== thirdInput) {
alert("Congratulations! You got all 3 numbers correct. You\'ve won £1,000!");
}
}
}
}
}

why doesn't it terminate?

var m_root : Node = root
private def insert(key: Int, value: Int): Node = {
if(m_root == null) {
m_root = Node(key, value, null, null)
}
var t : Node = m_root
var flag : Int = 1
while (t != null && flag == 1) {
if(key == t.key) {
t
}
else if(key < t.key) {
if(t.left == null) {
t.left = Node(key, value, null, null)
flag = 0
} else {
t = t.left
}
} else {
if(t.right == null) {
t.right = Node(key, value, null, null)
flag = 0
} else {
t = t.right
}
}
}
t
}
I wrote iterative version insert a node to binary search tree. I want to terminate when node is created, but it doesn't stop, because I think I didn't assign terminating condition. How to I edit my code to terminate when a node inserted in?
I'm not sure exactly what behaviour you want, but the cause is quite clear.
Your loop is a while condition, which will loop until t is null. So while t is non-null the loop will continue.
You only ever assign t to non-null values - in fact you're specifically checking for the null case and stopping it happening by creating a new node.
So either you need to reconsider your loop condition, or ensure t does in fact become null in some cases, depending on what your actual algorithm requirements are.
And since you're returning t at the bottom, I suggest the while condition is wrong; the only possible way this could terminate is if t is null at this point, so it would be pointless to return this anyway.
The first clause of your "if" statement in the loop
if(key == t.key) {
t
}
... does nothing if the comparison is true. It doesn't terminate the loop. The statement t is not synonymous with return t here. You can set flag = 0 at that point to terminate the loop.

Silly question about how you format long if statements

On long if statements where they take up more than one line, do you put the conditions like AND or OR on a new line like this:
if (something
&& something else)
Or like this:
if (something &&
something else)
For complex conditions, consider extracting it into a function or a variable:
if (complexCondition(foo)) { ..
As a bonus, the name of the function or variable can be used to communicate what the condition means. This makes your code easier to read.
I typically do it the second way, since I can line up the statements. However, either way is fine when you're writing code, as long as you're consistent.
I prefer a rendition of the first. My reasoning is that deleting a condition via cut/paste/comment for any testing purposes is easier. It's a lot easier to comment out a line than it is to delete the and from the line above and comment out a line. This is more when I'm doing where clauses in SQL than in an if statement in any other given language, but is similar.
Given my druthers, I'd avoid long if tests in the first place. I'd rather do something like:
bool fTest1 = A == B ;
bool fTest2 = C ;
bool fTest3 = f(1,2,3) ;
bool fSuccess = ( fTest1 | ftest2 ) & fTest3 ;
if ( fSuccess )
...
Otherwise something like this:
if ( A == B
&& ( C == D
|| E == F
)
&& Z > Y
) {
...
}
else
{
...
}
YMMV, of course.
The former is far easier to debug, test, log, etc.
I usually format using the IDE formatter and then rearrange a bit to make it look beautiful.
I'm working in VSC and recently managed to not only write, but make readable very long conditions in nested if statements. Just use brackets and new lines like this. It should make automatic indentations:
foreach ($panstwa as $key => $value) {
if (is_object($value)) {
if (
(
($value->checkbox1 === true) && (is_string($value->panstwoZListy)) && ($value->panstwoZListy !== 'none') && ($value->panstwo === '') && ($value->panstwoZListy !== '')
) ||
(
(
($value->checkbox2 === true &&
($value->checkbox2_1 === true || $value->checkbox2_2 === true || $value->checkbox2_3 === true || $value->checkbox2_4 === true || $value->checkbox2_5 === true || $value->checkbox2_6 === true)
) ||
($value->checkbox3 === true &&
($value->checkbox3_1 === true || $value->checkbox3_2 === true)
) ||
($value->checkbox4 === true &&
(
(
($value->checkbox4_1 === true || $value->checkbox4_2 === true || $value->checkbox4_3 === true || $value->checkbox4_4 === true || $value->checkbox4_5 === true || $value->checkbox4_6 === true || $value->checkbox4_7 === true) && ($value->checkbox4_8 === false)
) ||
(
($value->checkbox4_1 === false && $value->checkbox4_2 === false && $value->checkbox4_3 === false && $value->checkbox4_4 === false && $value->checkbox4_5 === false && $value->checkbox4_6 === false && $value->checkbox4_7 === false) && ($value->checkbox4_8 === true) && (sprawdzRegexTextInput($value->prawnieUzasadnionyInteres)) && (is_object($value->dokumentacjaOceny) || is_string($value->dokumentacjaOceny))
)
)
)
) &&
(is_string($value->panstwo)) && ($value->panstwoZListy === 'none') && ($value->panstwo !== '') && (sprawdzRegexTextInput($value->panstwo)
)
) &&
((is_int($value->panstwoid) && is_numeric($value->panstwoid)) || (is_bool($value->panstwoid) && $value->panstwoid === false)) &&
(is_bool($value->zmiana))
) {
echo "ok";
//nie robię nic
} else {
$flagaPanstwa = false;
}
} else {
$flagaPanstwa = false;
}
}

text box percentage validation in javascript

How can we do validation for percentage numbers in textbox .
I need to validate these type of data
Ex: 12-3, 33.44a, 44. , a3.56, 123
thanks in advance
sri
''''Add textbox'''''
<asp:TextBox ID="PERCENTAGE" runat="server"
onkeypress="return ispercentage(this, event, true, false);"
MaxLength="18" size="17"></asp:TextBox>
'''''Copy below function as it is and paste in tag..'''''''
<script type="text/javascript">
function ispercentage(obj, e, allowDecimal, allowNegative)
{
var key;
var isCtrl = false;
var keychar;
var reg;
if (window.event)
{
key = e.keyCode;
isCtrl = window.event.ctrlKey
}
else if (e.which)
{
key = e.which;
isCtrl = e.ctrlKey;
}
if (isNaN(key)) return true;
keychar = String.fromCharCode(key);
// check for backspace or delete, or if Ctrl was pressed
if (key == 8 || isCtrl)
{
return true;
}
ctemp = obj.value;
var index = ctemp.indexOf(".");
var length = ctemp.length;
ctemp = ctemp.substring(index, length);
if (index < 0 && length > 1 && keychar != '.' && keychar != '0')
{
obj.focus();
return false;
}
if (ctemp.length > 2)
{
obj.focus();
return false;
}
if (keychar == '0' && length >= 2 && keychar != '.' && ctemp != '10') {
obj.focus();
return false;
}
reg = /\d/;
var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
return isFirstN || isFirstD || reg.test(keychar);
}
</script>
You can further optimize this expression. Currently its working for all given patterns.
^\d*[aA]?[\-.]?\d*[aA]?[\-.]?\d*$
If you're talking about checking that a given text is a valid percentage, you can do one of a few things.
validate it with a regex like ^[0-9]+\.?[0-9]*$ then just convert that to a floating point value and check it's between 0 and 100 (that particular regex requires a zero before the decimal for values less than one but you can adapt it to handle otherwise).
convert it to a float using a method that raises an exception on invalid data (rather than just stopping at the first bad character.
use a convoluted regex which checks for valid entries without having to convert to a float.
just run through the text character by character counting numerics (a), decimal points (b) and non-numerics (c). Provided a is at least one, b is at most one, and c is zero, then convert to a float.
I have no idea whether your environment support any of those options since you haven't actually specified what it is :-)
However, my preference is to go for option 1, 2, 4 and 3 (in that order) since I'm not a big fan of convoluted regexes. I tend to think that they do more harm than good when thet become to complex to understand in less than three seconds.
Finally i tried a simple validation and works good :-(
function validate(){
var str = document.getElementById('percentage').value;
if(isNaN(str))
{
//alert("value out of range or too much decimal");
}
else if(str > 100)
{
//alert("value exceeded");
}
else if(str < 0){
//alert("value not valid");
}
}

Resources