I have two javscript files f1.js
and f2.js
in the same directory/folder which are part of a web application. f1
is responsible for displaying
jqxdatagrid with multiple rows and columns.
My goal :
I am basically trying to figure out a way to call function f2
when a user clicks on a row of the jqxdatagrid. All the logic related to grabbing row data is defined in f1.js
inside this line $("#dataDocumentPanel").on('rowclick',function(event){
My Attempt:
I was looking at this post Call variables from one javascript file to another So I declared var SUBTYPE
which will initialize mySubtype
.
In order to access the above value, I did the following in f2.js
var forf1 = new Object;
alert(forf1.mySubtype);
So, before doing anything, I want to check via alert whether I am getting the value of mySubtype
in f2.js
or not.
Please correct me if I am wrong but the reason because alert in f2.js
isn't working is because I feel like I would need to call the f2 file
when a user clicks on a particular row of jqxdatagrid. I mean something needs to happen on this line $("#dataDocumentPanel").on('rowclick',function(event){
?
Here are my two javascript files :
f1.js
function f1() {
var self = this;
this.urlKey = "showIDNumber";
this.getData = function (IDNumber_) {
//Some code related to ajax reques
.done(function (data_, textStatus_, jqXHR_) {
self.processdataDocuments(data_.data_document_list);
})
.fail(function (jqXHR_, textStatus_, errorThrown_) {
// some code here
});
};
// Initialize the page
this.initialize = function () {
self.getData(IDNumber);
};
this.processdataDocuments = function (collection_) {
var source =
{
localdata: collection_,
datatype: "array"
};
var dataAdapter = new $.jqx.dataAdapter(source, {
loadComplete: function (data) { },
loadError: function (xhr, status, error) { }
});
$("#dataDocumentPanel").jqxGrid(
// some code here to populate jqxgrid
});
// For getting the contents of a row, I am using jqxgrid approach as mentioned in their doc here :
// http://www.jqwidgets.com/getting-the-clicked-grid-row/
$("#dataDocumentPanel").on('rowclick',function(event){
var row = event.args.rowindex;
var datarow = $("#dataDocumentPanel").jqxGrid('getrowdata', row);
var jsonStringify = JSON.stringify(datarow,null,10);
alert(jsonStringify); // This alert displays the JSON data in a formatted manner
var obj = jQuery.parseJSON(response);
//alert("display Subtype "+obj.nc_subtype) // Works fine
var SUBTYPE = {
mySubtype : obj.nc_subtype
};
});
};
};
f2.js
function f2() {
var self = this;
var forf1 = new Object;
alert(forf1.mySubtype); // Trying to display obj.nc_subtype value from f1
this.getData = function (IDNumber_) {
// some code will be here
var ajaxRequest = jQuery.ajax({
// some code will be here
})
.done(function (data_, textStatus_, jqXHR_) {
// some code will be here
})
.fail(function (jqXHR_, textStatus_, errorThrown_) {
// some code will be here
});
};
}