Posts Tagged ‘JavaScript’

Many a times we come across a business case where we need to add multiple markers to Google Map. When markers added on map cross a thousand mark it slows down Google Map big time. In order to handle this scenario, I came up with my custom approach which I have tested with about 10000 points on the map.


Beautify XML String in JavaScript

Posted: September 28, 2015 by Sagar Wasule in JavaScript
Tags: ,

Ok so here is a scenario where for requirement I had to properly indent the string xml viz, beautify the xml string with proper indentation.

function formatXml(xml) {

var formatted = '';
var reg = /(>)\s*(<)(\/*)/g;
xml = xml.replace(/\r|\n/g, ''); //deleting already existing whitespaces
xml = xml.replace(reg, '$1\r\n$2$3');
var pad = 0;
jQuery.each(xml.split('\r\n'), function (index, node) {
var indent = 0;
if (node.match(/.+]*>$/)) {
indent = 0;
} else if (node.match(/^<\/\w/)) {
if (pad != 0) {
pad -= 1;
} else if (node.match(/^]*[^\/]>.*$/)) {
indent = 1;
} else {
indent = 0;

var padding = '';
for (var i = 0; i < pad; i++) {
padding += ' ';

formatted += padding + node + '\r\n';
pad += indent;

return formatted;

Finally the AngularJS team as provided the onFocus edit functionality in their plugin for Grid. The plugin that we will need to be used is ngGrid plugin you can check out this on AngularJS grid team website. The URL for the same is :




This scenario occured to me when the data returned from a WebMethod was huge. The WebMethod would return the data from its scope but in ajax call the response was accepted in error block. This ajax call was written in Extjs. The plugin used for ExtJs was 4.1


So this is the issue that most of the developers might be facing on day to day basis while development in javascript.
The issue is even after you made changes in your javascript file but still the old Javascript file is refered, which bugs your mind big time.
A simple solution to this issue is to clear the browser cache and run the application again, but this again is frustrating when your are under pressure to meet deadlines.

So I bring to you a good and simple solution to the issue.
Note: As I’m a .Net developer and uses Visual Studio 2010 I have tested this in Visual Studio 4.0 Environment with Internet Explorer and Google Chrome as browsers.

We generally refer our javascript file as below :

<script language=”javascript” src=”/scripts/myJavaScript.js” type=”text/javascript”></script>

I changed this reference to somewhat like I have mentioned here :

<script src=”@Url.Content(“~/Scripts/myJavaScript.js?” + DateTime.Now.ToString(“ddMMHHmmss”))” type=”text/javascript”></script>

And this works !!!!

NOTE: I implemented this and it worked for MVC3 Razor Engine application.

I have been saved from lot of frustration while development in script files. Hope this will save developers from some frustration.

JavaScript Keycodes

Posted: May 21, 2013 by Sagar Wasule in JavaScript, Programming Concepts
Tags: ,

Javascript is often used on the browser client side to perform simple tasks that would otherwise require a full postback to the server. Many of those simple tasks involve processing text or characters entered into a form element on a web page, and it is often necessary to know the javascript keycode associated with a character.


The below article was published on May 21, 2013. You can find my new post for Editable Grid using AngularJS – ngGrid Plugin at :…in-angularjs-2/
Let me know if you have any doubts or queries.

Old post on custom control created to work like OnFocus Editable grid is below :
So this is what was bugging my mind from last week or so , I was working on AngularJs in which I had to prepare an on focus grid. I used ngGrid plugin for the same. Actually it would had been too simple have ngGrid(AngularJs) team not remove the functionality on ‘enableCellFocusedEdit’. I refered to the example mentioned on their website . On this website they have mentioned an example ‘Edit On Focus Cell Selection Example’. I tried out various sources to gather whatever information to implement this functionality but I failed. I went across the issues which I found when I googled it ‘; but seems its not resolved till now.

Note: This is not exactly a grid provided by AngularJS team but an customised control created by me.




Here’s a list of sources of information for the different elements that comprise the 70-480 exam:

General Resources This is the complete source for video coverage of the exam, including information on the followup exam for building Windows Store apps with HTML5, CSS and Javascript. Go to the site to get a free voucher code to take the exam while supplies last! (As pointed out in David Pallmann’s blog.)

I found blog which is similar to what I was about to mention in this blog. (Yes, this isn’t free, but if you look at the course listing there is an entire section on HTML5, CSS3 and Javascript. You can always try the trial!)

(update): (This sample set includes a lot of information about both the 70-480 as well as 70-481)

Some of the links I put below will overlap with the other resources above, but I tried to find explanations that looked beneficial to me on links outside those already mentioned.