Page is Dirty using JavaScript

In the bad old days of desktop applications, every form object in the world had a Dirty property that let you easily check to see if the user had made any changes to the data on the form. It’s almost as easy with client-side code running in the Web browser, provided you use jQuery. This line finds every input tag and ties the tag’s change event to a JavaScript function called flagChanges:

$("input").change(function () 
            {
              flagChanges();
            });

Read more in Visual Studio Magazine;

Other References

https://www.c-sharpcorner.com/blogs/page-is-dirty-using-javascript1

Fonts vs PNG transparent images

Fonts are letters, numbers, and symbols designed using specific typefaces. They can apply to various design elements such as logos, headings, and body text. On the other hand, PNG (Portable Network Graphics) transparent designs are images with transparent backgrounds that can be layered over other graphics or backgrounds.

The main difference between font vs PNG transparent designs is their application. Font use to create typographic designs, while PNG transparent designs  use for creating image-based designs with transparency.

Fonts are ideal for creating text-heavy designs, while PNG transparent designs are perfect for creating graphics with intricate details such as icons, logos, and illustrations.

Since fonts are letters, numbers and symbols so it is possible they can not be rendered in some UI components. The rendering experience is an empty space with alternate text only. For example;

<a class="foo" title="Delete" href="#" onclick="foo.display(33);CancelEvent(event);\">
	<i class="fa fa-trash\"></i> Trash
</a>

Plus and Minu are universal fonts recognized by almost all components.

<a class="foo" title="Delete" href="#" onclick="foo.display(33);CancelEvent(event);\">
	<i class="fa fa-add\"></i> Trash
</a>

If a component doesn’t support font then + and – symbol will be rendered without any styles.

In the world of modern web, icons have become an indelible and integral part of UI design. Read about Font and SVG (Scalable vector graphics) icons. majority of the web development community prefers to use SVG icons;

Read more about Fonts Vs SVG here

Read about how to use SVG images in CSS and HTML here

Cascading Dropdown List

Create three dropdown lists, inside an HTML form.

The second and third dropdown list will display different options, depending on the value selected in the parent dropdown list.

Add HTML;

<form name="form1" id="form1" action="/action_page.php">
  Subjects: <select name="subject" id="subject">
    <option value="" selected="selected">Select subject</option>
  </select>
  <br><br>
  Topics: <select name="topic" id="topic">
    <option value="" selected="selected">Please select subject first</option>
  </select>
  <br><br>
  Chapters: <select name="chapter" id="chapter">
    <option value="" selected="selected">Please select topic first</option>
  </select>
  <br><br>
  <input type="submit" value="Submit">
</form>

Add JavaScript;

var subjectObject = {
  "Front-end": {
    "HTML": ["Links", "Images", "Tables", "Lists"],
    "CSS": ["Borders", "Margins", "Backgrounds", "Float"],
    "JavaScript": ["Variables", "Operators", "Functions", "Conditions"]
  },
  "Back-end": {
    "PHP": ["Variables", "Strings", "Arrays"],
    "SQL": ["SELECT", "UPDATE", "DELETE"]
  }
}
window.onload = function() {
  var subjectSel = document.getElementById("subject");
  var topicSel = document.getElementById("topic");
  var chapterSel = document.getElementById("chapter");
  for (var x in subjectObject) {
    subjectSel.options[subjectSel.options.length] = new Option(x, x);
  }
  subjectSel.onchange = function() {
    //empty Chapters- and Topics- dropdowns
    chapterSel.length = 1;
    topicSel.length = 1;
    //display correct values
    for (var y in subjectObject[this.value]) {
      topicSel.options[topicSel.options.length] = new Option(y, y);
    }
  }
  topicSel.onchange = function() {
    //empty Chapters dropdown
    chapterSel.length = 1;
    //display correct values
    var z = subjectObject[subjectSel.value][this.value];
    for (var i = 0; i < z.length; i++) {
      chapterSel.options[chapterSel.options.length] = new Option(z[i], z[i]);
    }
  }
}

Reference

https://www.w3schools.com/howto/howto_js_cascading_dropdown.asp

All about EJS TreeGrid

A JavaScript data grid with XML document. This is known as EJS TreeGrid.

Demos and installations are here;

https://www.treegrid.com/Doc/TreeGridHtml.html?Mark=html

Some tips and tricks;

For treegrid debugging (If we want to see what is the layout file and how the data is structured, call the layout or data directly)
http://localhost:5055/Finance/FileTableLayout?ProjectId=99

Here are some useful links;

https://www.treegrid.com/

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

https://www.treegrid.com/Examples/Html/AppPivotTable/PivotTable.html

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

Pivot a JavaScript Array: Convert a Column to a Row

Sometimes we need to convert a column to row in JavaScript array. It might be helpful to pass it as web service argument, generating chart dynamically or to display data in more meaningful way. In this post, we will create a method which converts a specified column to row in JavaScript array like below:

Consider the following array;

var arr = [
//["Product", "Year", "Sales"],
["Product 1", "2009", "1212"],
["Product 2", "2009", "522"],
["Product 1", "2010", "1337"],
["Product 2", "2011", "711"],
["Product 2", "2012", "2245"],
["Product 3", "2012", "1000"]
];

Use following method to convert this array;

function getPivotArray(dataArray, rowIndex, colIndex, dataIndex) {
        //Code from https://techbrij.com
        var result = {}, ret = [];
        var newCols = [];
        for (var i = 0; i < dataArray.length; i++) {
 
            if (!result[dataArray[i][rowIndex]]) {
                result[dataArray[i][rowIndex]] = {};
            }
            result[dataArray[i][rowIndex]][dataArray[i][colIndex]] = dataArray[i][dataIndex];
 
            //To get column names
            if (newCols.indexOf(dataArray[i][colIndex]) == -1) {
                newCols.push(dataArray[i][colIndex]);
            }
        }
 
        newCols.sort();
        var item = [];
 
        //Add Header Row
        item.push('Item');
        item.push.apply(item, newCols);
        ret.push(item);
 
        //Add content 
        for (var key in result) {
            item = [];
            item.push(key);
            for (var i = 0; i < newCols.length; i++) {
                item.push(result[key][newCols[i]] || "-");
            }
            ret.push(item);
        }
        return ret;
    }

In above method:
dataArray: Array to be converted
rowIndex: Index of column in array which is to be kept as first column
colIndex: Index of column whose values to be converted as columns in the output array.
dataIndex: Index of column whose values to be used as data (displayed in tabular/grid format).

The logic of method is simple. First it iterates the given array and create a result object of [rowIndex],[colIndex] = [dataIndex] format so that it can be fetched easily by using associative array like syntax. In the same iteration, we put unique values of colIndex in newCols array which will be used to create new columns. After this loop, we will get result object and newCols array. Now create a return array (ret), push newCols values for Header data and iterate result object, push values in ret object. Finally, ret variable will have the converted array.

Use this function to show HTML table;

function arrayToHTMLTable(myArray) {
           var result = "<table border='1' cellpadding='7' cellspacing='0'>";
           for (var i = 0; i < myArray.length; i++) {
               result += "<tr>";
               for (var j = 0; j < myArray[i].length; j++) {
                   result += "<td>" + myArray[i][j] + "</td>";
               }
               result += "</tr>";
           }
           result += "</table>";
 
           return result;
       }       

Add following on HTML side;

<h2>Original Array</h2>
   <div id="orgTable"></div>
 
   <h2>Converted Array</h2>
   <div id="pivotTable"></div>

jQuery to show the results;

$(function () {
          var output = getPivotArray(arr, 0, 1, 2);
          $('#orgTable').html(arrayToHTMLTable(arr));
          $('#pivotTable').html(arrayToHTMLTable(output));
      });

Reference

https://www.cnblogs.com/vvull/p/14744863.html

https://medium.com/@saravanan16498/pivot-and-group-data-sk-yazhini9798-4a63e5cc3dd3