jQuery UI Widgets › Forums › Grid › dropdown column in gird
Tagged: dropdown editor, dropdownlist editor
This topic contains 10 replies, has 2 voices, and was last updated by Peter Stoev 12 years, 2 months ago.
-
Authordropdown column in gird Posts
-
function GetColumnsForDataSourceMapping() {
var columns = new Array();
var data = new Array();
for (var i = 0; i < jsonMappingObj.length; i++) {
data.push({
“Text”: jsonMappingObj[i].DataSourceColName[0].Text,
“Value”: jsonMappingObj[i].DataSourceColName[0].Text
});// console.log(jsonMappingObj[i].DataSourceColName[0].Text);}
var dropDownListSource =
{
datatype: “json”,
datafields: [
{ name: ‘Text’ },
{ name: ‘Value’ }
],
id: ‘Value’,
localdata: data
};
console.log(‘dropDownListSource’);
console.log(dropDownListSource);var dropdownListAdapter = new $.jqx.dataAdapter(dropDownListSource, { autoBind: true, async: false });
columns.push({
text: ‘Variable Data Names’,
datafield: ‘VariableDataNames’,
“width”: 200
});columns.push({
text: ‘Data Source Names ‘,
datafield: ‘Value’,
“width”: 200,
columntype: ‘dropdownlist’,
createeditor: function(row, cellvalue, editor) {
editor.jqxDropDownList({ displayMember: ‘Text’, valueMember: ‘Value’, source: dropdownListAdapter });
}
});columns.push({
text: ‘Sample Data From Data Source’,
datafield: ‘SampleData’,
“width”: 230
});
console.log(columns);
return columns;
}function GetdataForDataSourceMapping(jsonMappingObj) {
// prepare the data
var data = new Array();for (var i = 0; i < jsonMappingObj.length; i++) {
var row = {};
//console.log(jsonMappingObj[i].TemplateDisplayName[0].Text);
//console.log(jsonMappingObj[i].DataSourceColName[0].Text);
row[‘VariableDataNames’] = jsonMappingObj[i].TemplateDisplayName[0].Text;
//row[‘DataSourceNames’] = jsonMappingObj[i].DataSourceColName[0].Text;
row[‘SampleData’] = jsonMappingObj[i].SampleData[0].Text;
data[i] = row;
}var source =
{
datatype: “array”,
localdata: data
};
return source;}
function BindDataSourcemappingGrid(theme,columns,source) {
// initialize jqxGrid
$(“#jqxgridMapping”).jqxGrid(
{
width: 630,
source: source,
theme: theme,
columns: columns,
pageable: true
});
}Below is the result of console.log(dropDownListSource);I am doing something wrong. i am not able to see data in other columns but there is no data in dropdown column.Please suggest.Object- datafields: Array[2]
- datatype: “json”
- id: “Value”
- loadallrecords: true
- localdata: Array[19]
- 0: Object
- Text: “FirstName”
- Value: “FirstName”
- __proto__: Object
- 1: Object
- Text: “LastName”
- Value: “LastName”
- __proto__: Object
- 2: Object
- 3: Object
- 4: Object
- 5: Object
- 6: Object
- 7: Object
- 8: Object
- 9: Object
- 10: Object
- 11: Object
- 12: Object
- 13: Object
- 14: Object
- 15: Object
- 16: Object
- 17: Object
- 18: Object
- length: 19
- __proto__: Array[0]
- record: “”
- recordendindex: 0
- recordstartindex: 0
- root: “”
- __proto__: Object
Hi akansha,
It is possible to have DropDownList in a column, only in editable Grid.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comthanks!. I have changed the grid to editable.
i have only 2 columns in grid 1 textbox and 1 dropdown. and there is a button. On click of button i want the current state of grid, whatever user has modified. below mentioned function is not giving the current state , rather it is giving me original state.
function MapButtonClick() {
var data = $(‘#jqxgridMapping’).jqxGrid(‘getrowdata’, 0);
var rows = $(‘#jqxgridMapping’).jqxGrid(‘getrows’);
console.log(data);
console.log(rows);
}Hi akansha,
This is already implemented in the Popup Editing demo. I suggest you to take a look at it. When the user clicks a button, the window’s fields are updated with the row’s data.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comi saw that. But the problem is button is outside of the grid. And i want all rows with modified values in an object to send it back to server.
i tried
var rows = $(‘#jqxgridMapping’).jqxGrid(‘getrows’);but it gives me old values of dropdown.
Hi akansha,
It does not matter that the button is outside the Grid. It is a button and it does some action on click. The action is the same as in the popup editing demo. If you edited a cell and the cell is not in edit mode, the ‘getrows’ will return all rows including the edited value.
Example:
<!DOCTYPE html><html lang="en"><head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.edit.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcalendar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxnumberinput.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdatetimeinput.js"></script> <script type="text/javascript" src="../../jqwidgets/globalization/jquery.global.js"></script> <script type="text/javascript" src="../../scripts/gettheme.js"></script> <script type="text/javascript" src="generatedata.js"></script> <script type="text/javascript"> $(document).ready(function () { var theme = getTheme(); // prepare the data var data = generatedata(200); var source = { localdata: data, datatype: "array", updaterow: function (rowid, rowdata) { // synchronize with the server - send update command } }; var dataAdapter = new $.jqx.dataAdapter(source); // initialize jqxGrid $("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, editable: true, theme: theme, selectionmode: 'singlecell', columns: [ { text: 'First Name', columntype: 'textbox', datafield: 'firstname', width: 90 }, { text: 'Last Name', datafield: 'lastname', columntype: 'textbox', width: 90 }, { text: 'Product', columntype: 'dropdownlist', datafield: 'productname', width: 177 }, { text: 'Available', datafield: 'available', columntype: 'checkbox', width: 67 }, { text: 'Ship Date', datafield: 'date', columntype: 'datetimeinput', width: 90, cellsalign: 'right', cellsformat: 'd', validation: function (cell, value) { var year = value.getFullYear(); if (year >= 2013) { return { result: false, message: "Ship Date should be before 1/1/2013" }; } return true; } }, { text: 'Quantity', datafield: 'quantity', width: 70, cellsalign: 'right', columntype: 'numberinput', validation: function (cell, value) { if (value < 0 || value > 150) { return { result: false, message: "Quantity should be in the 0-150 interval" }; } return true; }, initeditor: function (row, cellvalue, editor) { editor.jqxNumberInput({ decimalDigits: 0, digits: 3 }); } }, { text: 'Price', datafield: 'price', width: 65, cellsalign: 'right', cellsformat: 'c2', columntype: 'numberinput', validation: function (cell, value) { if (value < 0 || value > 15) { return { result: false, message: "Price should be in the 0-15 interval" }; } return true; }, initeditor: function (row, cellvalue, editor) { editor.jqxNumberInput({ digits: 3 }); } } ] }); $("#Button").click(function () { var rows = $("#jqxgrid").jqxGrid('getrows'); }); }); </script></head><body class='default'> <div id='jqxWidget'> <div id="jqxgrid"></div> <input type="button" value="Button" id="Button" /> </div></body></html>
Edit any cell, for example the top-left one and click the button. The rows[0][‘firstname’] will return the new value.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comIn order to enter in edit mode, select a grid cell and start typing, "Click" or press the "Enter" or "F2" keys. You
can also navigate through the cells with the "Tab" and "Shift + Tab" key combinations. To cancel the cell editing, press the "Esc" key. To save
the changes press the "Enter" key or select another Grid cell. Pressing the 'Space' key when a checkbox cell is selected will toggle the check state.$(document).ready(function () {
var theme = '';// prepare the data
var data = generatedata(200);var source =
{
localdata: data,
datatype: "array",
updaterow: function (rowid, rowdata) {
// synchronize with the server - send update command
}
};var dataAdapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$("#jqxgrid").jqxGrid(
{
width: 670,
source: dataAdapter,
editable: true,
theme: theme,
selectionmode: 'singlecell',
columns: [
{ text: 'First Name', columntype: 'textbox', datafield: 'firstname', width: 90 },
{ text: 'Last Name', datafield: 'lastname', columntype: 'textbox', width: 90 },
{ text: 'Product', columntype: 'dropdownlist', datafield: 'productname', width: 177},
{ text: 'Available', datafield: 'available', columntype: 'checkbox', width: 67 },
{ text: 'Ship Date', datafield: 'date', columntype: 'datetimeinput', width: 90, cellsalign: 'right', cellsformat: 'd',
validation: function (cell, value) {
var year = value.getFullYear();
if (year >= 2013) {
return { result: false, message: "Ship Date should be before 1/1/2013" };
}
return true;
}
},
{ text: 'Quantity', datafield: 'quantity', width: 70, cellsalign: 'right', columntype: 'numberinput',
validation: function (cell, value) {
if (value 150) {
return { result: false, message: "Quantity should be in the 0-150 interval" };
}
return true;
},
initeditor: function (row, cellvalue, editor) {
editor.jqxNumberInput({ decimalDigits: 0, digits: 3 });
}
},
{ text: 'Price', datafield: 'price', width: 65, cellsalign: 'right', cellsformat: 'c2', columntype: 'numberinput',
validation: function (cell, value) {
if (value 15) {
return { result: false, message: "Price should be in the 0-15 interval" };
}
return true;
},
initeditor: function (row, cellvalue, editor) {
editor.jqxNumberInput({ digits: 3 });
}}
]
});// events
$("#jqxgrid").bind('cellbeginedit', function (event) {
var args = event.args;
$("#cellbegineditevent").html("Event Type: cellbeginedit, Column: " + args.datafield + ", Row: " + (1 + args.rowindex) + ", Value: " + args.value);
});$("#jqxgrid").bind('cellendedit', function (event) {
var args = event.args;
$("#cellendeditevent").html("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (1 + args.rowindex) + ", Value: " + args.value);
});
});function MapButtonClick() {
var data = $('#jqxgrid').jqxGrid('getrowdata', 0);
var rows = $('#jqxgrid').jqxGrid('getrows');
console.log(data);
console.log(rows[0].productname);
alert(rows[0].productname);}
please try this example.It is still giving me old value of product, not the modified one.
.
$(document).ready(function () {
var theme = ”;// prepare the data
var data = generatedata(200);var source =
{
localdata: data,
datatype: “array”,
updaterow: function (rowid, rowdata) {
// synchronize with the server – send update command
}
};var dataAdapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$(“#jqxgrid”).jqxGrid(
{
width: 670,
source: dataAdapter,
editable: true,
theme: theme,
selectionmode: ‘singlecell’,
columns: [
{ text: ‘First Name’, columntype: ‘textbox’, datafield: ‘firstname’, width: 90 },
{ text: ‘Last Name’, datafield: ‘lastname’, columntype: ‘textbox’, width: 90 },
{ text: ‘Product’, columntype: ‘dropdownlist’, datafield: ‘productname’, width: 177},
{ text: ‘Available’, datafield: ‘available’, columntype: ‘checkbox’, width: 67 },
{ text: ‘Ship Date’, datafield: ‘date’, columntype: ‘datetimeinput’, width: 90, cellsalign: ‘right’, cellsformat: ‘d’,
validation: function (cell, value) {
var year = value.getFullYear();
if (year >= 2013) {
return { result: false, message: “Ship Date should be before 1/1/2013” };
}
return true;
}
},
{ text: ‘Quantity’, datafield: ‘quantity’, width: 70, cellsalign: ‘right’, columntype: ‘numberinput’,
validation: function (cell, value) {
if (value 150) {
return { result: false, message: “Quantity should be in the 0-150 interval” };
}
return true;
},
initeditor: function (row, cellvalue, editor) {
editor.jqxNumberInput({ decimalDigits: 0, digits: 3 });
}
},
{ text: ‘Price’, datafield: ‘price’, width: 65, cellsalign: ‘right’, cellsformat: ‘c2’, columntype: ‘numberinput’,
validation: function (cell, value) {
if (value 15) {
return { result: false, message: “Price should be in the 0-15 interval” };
}
return true;
},
initeditor: function (row, cellvalue, editor) {
editor.jqxNumberInput({ digits: 3 });
}}
]
});// events
$(“#jqxgrid”).bind(‘cellbeginedit’, function (event) {
var args = event.args;
$(“#cellbegineditevent”).html(“Event Type: cellbeginedit, Column: ” + args.datafield + “, Row: ” + (1 + args.rowindex) + “, Value: ” + args.value);
});$(“#jqxgrid”).bind(‘cellendedit’, function (event) {
var args = event.args;
$(“#cellendeditevent”).html(“Event Type: cellendedit, Column: ” + args.datafield + “, Row: ” + (1 + args.rowindex) + “, Value: ” + args.value);
});
});function MapButtonClick() {
var data = $(‘#jqxgrid’).jqxGrid(‘getrowdata’, 0);
var rows = $(‘#jqxgrid’).jqxGrid(‘getrows’);
console.log(data);
console.log(rows[0].productname);
alert(rows[0].productname);
}.
$(document).ready(function () {
var theme = '';// prepare the data
var data = generatedata(200);var source =
{
localdata: data,
datatype: "array",
updaterow: function (rowid, rowdata) {
// synchronize with the server - send update command
}
};var dataAdapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$("#jqxgrid").jqxGrid(
{
width: 670,
source: dataAdapter,
editable: true,
theme: theme,
selectionmode: 'singlecell',
columns: [
{ text: 'First Name', columntype: 'textbox', datafield: 'firstname', width: 90 },
{ text: 'Last Name', datafield: 'lastname', columntype: 'textbox', width: 90 },
{ text: 'Product', columntype: 'dropdownlist', datafield: 'productname', width: 177},
{ text: 'Available', datafield: 'available', columntype: 'checkbox', width: 67 },
{ text: 'Ship Date', datafield: 'date', columntype: 'datetimeinput', width: 90, cellsalign: 'right', cellsformat: 'd',
validation: function (cell, value) {
var year = value.getFullYear();
if (year >= 2013) {
return { result: false, message: "Ship Date should be before 1/1/2013" };
}
return true;
}
},
{ text: 'Quantity', datafield: 'quantity', width: 70, cellsalign: 'right', columntype: 'numberinput',
validation: function (cell, value) {
if (value 150) {
return { result: false, message: "Quantity should be in the 0-150 interval" };
}
return true;
},
initeditor: function (row, cellvalue, editor) {
editor.jqxNumberInput({ decimalDigits: 0, digits: 3 });
}
},
{ text: 'Price', datafield: 'price', width: 65, cellsalign: 'right', cellsformat: 'c2', columntype: 'numberinput',
validation: function (cell, value) {
if (value 15) {
return { result: false, message: "Price should be in the 0-15 interval" };
}
return true;
},
initeditor: function (row, cellvalue, editor) {
editor.jqxNumberInput({ digits: 3 });
}}
]
});// events
$("#jqxgrid").bind('cellbeginedit', function (event) {
var args = event.args;
$("#cellbegineditevent").html("Event Type: cellbeginedit, Column: " + args.datafield + ", Row: " + (1 + args.rowindex) + ", Value: " + args.value);
});$("#jqxgrid").bind('cellendedit', function (event) {
var args = event.args;
$("#cellendeditevent").html("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (1 + args.rowindex) + ", Value: " + args.value);
});
});function MapButtonClick() {
var data = $('#jqxgrid').jqxGrid('getrowdata', 0);
var rows = $('#jqxgrid').jqxGrid('getrows');
console.log(data);
console.log(rows[0].productname);
alert(rows[0].productname);
}I dont know why full code is not getting copied. Sorry for 2 many reply.
For code formatting, take a look at this post: http://www.jqwidgets.com/community/topic/code-formatting/. In addition, did you try the code from my post? Do you also use jQWidgets 2.3.1?
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.