Example 8


This example shows how a case sensitive search of the individual's attributes (e.g. age, name) can be implemented. The user can enter a search string into the 'Search for...' text area located above the pedigree. A more sophisticated search could be based on this for example by additionally providing 'case insensitive' and 'search and replace' options. When the 'Search' button is clicked or 'enter' pressed in the 'Search for...' text box the following search method is called:


// search pedigree data with the given search text
function search_pedigree_data(search) {
	var pedigree = pedcache.current(opts);		// current pedigree data displayed
	var html = "";
	for(var p=0; p<pedigree.length; p++){		// loop over each person in the pedigree
		var found = false;
		var attr = '';
		$.each(pedigree[p], function(key, value) {	// loop over individual's data
			if(search == key || search == value || 
			   key.indexOf(search) !== -1 || (""+value).indexOf(search) !== -1) {
				found = true;
				attr += "<strong><font color='red'>"+ key + ":" + value + "; " + "</font></strong>";
			} else {
				attr += key + ":" + value + "; ";
			}
		});
		if(found) {
			html += attr + "<br>";
		}
	}
	if(html !== '') {
		$('#search_result').html(html);		// display matches found
	} else {
		$('#search_result').html("No matches");	// no matches found
	}
}