Forum
21:36
22/01/2013
function createDataGrid(data)
{
var mydata = getJSONObject(data);
mydata,
grid = $("#list4"),
getUniqueNames = function(columnName) {
// Maybe this line could be moved outside the function
// If the data is really huge then the entire segregation could
// be done in a single loop storing each unique column
// in a map of columnNames -> unique values
var data = grid.jqGrid('getGridParam', 'data');
var uniqueTexts = [], text, textsMap = {}, i;
for (i = 0; i < data.length; i++) {
text = data[i][columnName];
if (text !== undefined && textsMap[text] === undefined) {
// to test whether the texts is unique we place it in the map.
textsMap[text] = true;
uniqueTexts.push(text);
}
}
// Object.keys(textsMap); Does not work with IE8:
return uniqueTexts;
}, buildSearchSelect = function(uniqueNames) {
// alert("uniqueNames:::::"+uniqueNames);
var values=":All";
$.each (uniqueNames, function() {
values += ";" + this + ":" + this;
// alert("values:::::"+values);
});
// alert("Final values:::::"+values);
return values;
},
setSearchSelect = function(columnName) {
grid.jqGrid('setColProp', columnName,
{
stype: 'select',
searchoptions: {
value:buildSearchSelect(getUniqueNames(columnName)),
sopt:['eq']
}
}
);
};
// make search false .... make sortable false .. if not reqd for any of the columns
grid.jqGrid({
data: mydata,
datatype: "local",
height: 'auto',
autowidth: true,
colNames:['Name', 'Address','City','State','Zip'],
colModel:[
{ name:'customerName',index:'customerName' , width: 60, align: "center" , sortable: true },
{ name:'billingAddressLine1',index:'billingAddressLine1' , width: 100 , align: "center" , sortable: true},
{ name:'billingCity',index:'billingCity', width:80 , align: "center", sortable: true},
{ name:'billingState',index:'billingState', width:80, align: "center" , sortable: true},
{ name:'billingZip',index:'billingZip', width:80 , align: "center", search:false, sortable: false}
],
scroll: true,
rowNum:10,
rowList:[10,20,300],
pager: '#pager',
sortname: 'customerName',
viewrecords: true,
sortorder: 'desc',
ignoreCase: true,
gridview: true,
rownumbers: true,
height: "auto",
caption: "Setting filter in the filter toolbar"
}).jqGrid('navGrid','#pager',
{edit:false, add:false, del:false, search:false, refresh:false});
setSearchSelect('customerName');
setSearchSelect('billingState');
grid.jqGrid('setColProp', 'Name',
{
searchoptions: {
sopt:['cn'],
dataInit: function(elem) {
$(elem).autocomplete({
source:getUniqueNames('Name'),
delay:0,
minLength:0
});
}
}
});
grid.jqGrid('filterToolbar',
{stringResult:true, searchOnEnter:true, defaultSearch:"cn"});
}
Most Users Ever Online: 715
Currently Online:
59 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66