jQuery UI Widgets › Forums › Grid › How to include If statement in Grid
This topic contains 1 reply, has 1 voice, and was last updated by Keshavan 12 years, 3 months ago.
-
Author
-
Hi,
I have a grid in which the first cell is of col type ‘dropdownlist’, the dropdownlist will display ‘GroupName’ from a different table and i will store the corresponding ‘GroupCompanycode’ in the Grid for updating the main table(Company table),
issue is the code hangs in ‘ADD’ mode, as the ‘GroupColomnId’ field would be null, obviously it works fine edit mode.
I intend to use an if statement in data source definition and then accordingly in Grid Initialization,
the 2 places i need to include if statement are ,
1) datafiled definiton,
{ name: ‘Group’, value: ‘GroupCompanyId’, values: { source: dataAdapater1.records, value: ‘GroupCompanyId’, name: ‘GroupName’} },2) Grid Initialization,
{
text: ‘Group’, datafield: ‘GroupCompanyId’, displayfield: ‘Group’, columntype: ‘dropdownlist’, width: 200,
createeditor: function (row, cellvalue, editor)
{
editor.jqxDropDownList({ source: dataAdapter1, displayMember: ‘Group’, valueMember: ‘GroupCompanyId’ })
}
},Please help, / suggest alternates, below is the full code,
Thanks,
Keshavan
This example shows how to bind with Db
$(document).ready(function () {
// prepare data from external GroupCompany entity
var z = 0;var source =
{
datatype: “json”,
datafields:
[
{ name: ‘GroupCompanyId’ },
{ name: ‘GroupName’ },
],
id: ‘GroupCompanyId’,
url: ‘GroupCompany/GetSemiGroupCompanies’,
async: false
}
var dataAdapater1 = new $.jqx.dataAdapter(source, {
autoBind: true
});
var data = {};
var GroupCompanyIds = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var CompanyNames = [“Nancy”, “Andrew”, “Janet”, “Margaret”, “Steven”, “Michael”, “Robert”, “Laura”, “Anne”];
var Unitss = [111, 555, 777, 888, 999.100, 11100];
var Phones = [“Davolio”, “Fuller”, “Leverling”, “Peacock”, “Buchanan”, “Suyama”, “King”, “Callahan”, “Dodsworth”];
var EmailIds = [“Davolio”, “Fuller”, “Leverling”, “Peacock”, “Buchanan”, “Suyama”, “King”, “Callahan”, “Dodsworth”];
var AddressLine1s = [“Sales Representative”, “Vice President, Sales”, “Sales Representative”, “Sales Representative”, “Sales Manager”, “Sales Representative”, “Sales Representative”, “Inside Sales Coordinator”, “Sales Representative”];
var AddressLine2s = [“507 – 20th Ave. E. Apt. 2A”, “908 W. Capital Way”, “722 Moss Bay Blvd.”, “4110 Old Redmond Rd.”, “14 Garrett Hill”, “Coventry House”, “Miner Rd.”, “Edgeham Hollow”, “Winchester Way”, “4726 – 11th Ave. N.E.”, “7 Houndstooth Rd.”];
var Zips = [“Seattle”, “Tacoma”, “Kirkland”, “Redmond”, “London”, “London”, “London”, “Seattle”, “London”];
var Countrys = [“USA”, “USA”, “USA”, “USA”, “UK”, “UK”, “UK”, “USA”, “UK”];
var Cultures = [“USA”, “USA”, “USA”, “USA”, “UK”, “UK”, “UK”, “USA”, “UK”];
var Miscellaneous1s = [“USA”, “USA”, “USA”, “USA”, “UK”, “UK”, “UK”, “USA”, “UK”];
var Miscellaneous2s = [“USA”, “USA”, “USA”, “USA”, “UK”, “UK”, “UK”, “USA”, “UK”];
var Miscellaneous3s = [“USA”, “USA”, “USA”, “USA”, “UK”, “UK”, “UK”, “USA”, “UK”];
var generaterow = function (id) {
var row = {};
row[“CompanyId”] = id;
row[“GroupCompanyId”] = 1;
row[“CompanyName”] = ” “;
row[“Unit”] = 0;
row[“Phone”] = ” “;
row[“EmailId”] = ” “;
row[“AddressLine1″] = ” “;
row[“AddressLine2″] = ” “;
row[“Zip”] = ” “;
row[“Country”] = ” “;
row[“Culture”] = ” “;
row[“Miscellaneous1″] = ” “;
row[“Miscellaneous2″] = ” “;
row[“Miscellaneous3″] = ” “;
return row;
}
var source1 =
{
datatype: “json”,
datafields:
[
{ name: ‘CompanyId’ },
{ name: ‘Group’, value: ‘GroupCompanyId’, values: { source: dataAdapater1.records, value: ‘GroupCompanyId’, name: ‘GroupName’} },
{ name: ‘GroupCompanyId’, type: ‘int’ },
{ name: ‘Unit’ },
{ name: ‘Phone’ },
{ name: ‘EmailId’ },
{ name: ‘AddressLine1’ },
{ name: ‘AddressLine2’ },
{ name: ‘Zip’ },
{ name: ‘Country’ },
{ name: ‘Culture’ },
{ name: ‘Miscellaneous1’ },
{ name: ‘Miscellaneous2’ },
{ name: ‘Miscellaneous3’ },
],
id: ‘CompanyId’,
url: ‘Company/GetCompanies’,
addrow: function (rowid, rowdata, position, commit) {
// synchronize with the server – send insert command
$.ajax({
cache: false,
dataType: ‘json’,
url: ‘Company/Add’,
data: rowdata,
type: “POST”,
success: function (data, status, xhr) {
// insert command is executed.
commit(true);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
commit(false);
}
});
},
deleterow: function (rowid, commit) {
// synchronize with the server – send delete command
$.ajax({
dataType: ‘json’,
cache: false,
url: ‘/Company/Delete/5’,
type: “POST”,
success: function (data, status, xhr) {
// delete command is executed.
commit(true);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.statusText);
commit(false);
}
});
},
updaterow: function (rowid, rowdata, commit) {
// synchronize with the server – send update command
{
$.ajax(
{
cache: false,
dataType: ‘json’,
url: ‘Company/Update’,
data: rowdata,
type: “POST”,
success: function (data, status, xhr) {
// update command is executed.
alert(success);
commit(true);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
commit(false);
}
}
);
}
}
}
var dataAdapater = new $.jqx.dataAdapter(source1);
// initialize jqxGrid../../JqWidgets/index.htm
$(“#jqxgrid”).jqxGrid(
{
width: 950,
height: 350,
source: source1,
theme: ‘ui-smoothness’,
editable: true,
editmode: ‘selectedcell’,
rowdetails: true,
rowsheight: 20,
columns:
[
{
text: ‘Group’, datafield: ‘GroupCompanyId’, displayfield: ‘Group’, columntype: ‘dropdownlist’, width: 200,
createeditor: function (row, cellvalue, editor)
{
editor.jqxDropDownList({ source: dataAdapter1, displayMember: ‘Group’, valueMember: ‘GroupCompanyId’ })
}
},
{ text: ‘Company’, datafield: ‘CompanyName’, width: 215 },
{ text: ‘Unit’, datafield: ‘Unit’, width: 80 },
{ text: ‘Phone’, datafield: ‘Phone’, width: 180 },
{ text: ‘Email ‘, datafield: ‘EmailId’, width: 180 },
{ text: ‘Address ‘, datafield: ‘AddressLine1’, width: 100 },
{ text: ‘ ‘, datafield: ‘AddressLine2’, width: 100 },
{ text: ‘Zip’, datafield: ‘Zip’, width: 80 },
{ text: ‘Country’, datafield: ‘Country’, width: 80 },
{ text: ‘Culture’, datafield: ‘Culture’, width: 80 },
{ text: ‘Other’, datafield: ‘Miscellaneous1’, width: 80 },
{ text: ‘ ‘, datafield: ‘Miscellaneous2’, width: 80 },
{ text: ‘ ‘, datafield: ‘Miscellaneous3’, width: 80 },
]
});
$(“#addrowbutton”).jqxButton();
$(“#deleterowbutton”).jqxButton();
$(“#updaterowbutton”).jqxButton();// update row.
$(“#updaterowbutton”).bind(‘click’, function () {
/*var datarow s generaterow(); */
var selectedrowindex = $(“#jqxgrid”).jqxGrid(‘getselectedrowindex’);
var rowscount = $(“#jqxgrid”).jqxGrid(‘getdatainformation’).rowscount;
if (selectedrowindex >= 0 && selectedrowindex = 0 && selectedrowindex < rowscount) {
var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);
$("#jqxgrid").jqxGrid('deleterow', id);
}
});
});Please Ignore this post
-
AuthorPosts
You must be logged in to reply to this topic.