jQuery.param()

Create a serialized representation of an array, a plain object, or a jQuery object suitable for use in a URL query string or Ajax request. In case a jQuery object is passed, it should contain input elements with name/value properties.

// <=1.3.2:
$.param({ a: [ 2, 3, 4 ] }); // "a=2&a=3&a=4"
// >=1.4:
$.param({ a: [ 2, 3, 4 ] }); // "a[]=2&a[]=3&a[]=4"
 
// <=1.3.2:
$.param({ a: { b: 1, c: 2 }, d: [ 3, 4, { e: 5 } ] });
// "a=[object+Object]&d=3&d=4&d=[object+Object]"
 
// >=1.4:
$.param({ a: { b: 1, c: 2 }, d: [ 3, 4, { e: 5 } ] });
// "a[b]=1&a[c]=2&d[]=3&d[]=4&d[2][e]=5"

Reference

Read more on jQuery Web site

Using Razor, how do I render a Boolean to a JavaScript variable?

This is our C# model;

public class Foo
{
  public bool IsAllowed {get; set;} = false;
}

We would like to read this property in JS;

let isAllowed = '@Model.IsAllowed' === '@true';
if (isAllowed)
{
    console.log('Allowed reading..');
}
else
{
    console.log('Reading not allowed..');
}

Reference

https://stackoverflow.com/questions/14448604/using-razor-how-do-i-render-a-boolean-to-a-javascript-variable

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean

Treegrid Row Filter

When we apply filters in treegrid, Row property is set to true. Let’s say we have 100 records of VA and DC equally distributed 50/50. If we don’t apply any filter then Row Visible property of all records is true.

If we apply VA filter then 50 records visible property will be true and remining 50 will be false.

The twist is hidden rows. Let’s say we have 2 DC records selected. We apply VA filter then row visible property of 52 records will be selected. To get a clean picture we need to reset DC hidden rows.

For custom implementation OnAfterValueChanged Event. This is a generic event and can be used for anything (cells, rows etc).

Here is a sample code snippt;

$.each(grd.Rows, function (index, row) {
   if (row.Visible == true) {
     grd.SetValue(rw, 'Select', val, true);
   }
}

Reference

https://www.treegrid.com/Doc/RowAPI.htm

Default value for a boolean parameter in JavaScript function

See following example;

You could skip the ternary, and evaluate the “not not x”, e.g. !!x.

If x is undefine, !x is true, so !!x becomes false again. If x is true !x is false so !!x is true.

function logBool(x) {
    x = !!x;
    console.log(x);
}

var a, b = false, c = true;
logBool(a); // false
logBool(b); // false
logBool(c); // true

https://stackoverflow.com/questions/24332839/set-a-default-value-for-a-boolean-parameter-in-a-javascript-function