jQuery UI Widgets › Forums › Grid › Grid Editors ComboBox Request
Tagged: combobox editor
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 12 years, 3 months ago.
-
Author
-
I have a working Grid ComboBox Editor based on a Foreign Key. I am using two columns to pull it off and one is hidden. Currently it is using the event.args.index and am asking you to provide the value as well. I understand how you only bind one value to the grid and that is fine. But we should have the choice between the index or value. Here is my code.. Sorry for the amount of code, I will try to keep it simple….
This is where on select I get the ComboBox index and it will only work if your dbID match the ComboBox Indexes.
stateIndex = event.args.indexWould rather get something like this
var item = event.args.item;
if (item) {
stateIndex = item.value;
}I am sure this could be improved…. But works….
**********************
****** StateJSON ******
**********************require_once “../jq-config.php”;
require_once ABSPATH . “php/jqGrid.php”;
require_once ABSPATH . “php/jqGridPdo.php”;
$conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD);$preparedStatement = $conn->prepare(“SELECT ID, State FROM States Order by State”);
$preparedStatement->execute();$result = $preparedStatement->fetchAll();
echo json_encode($result);
**********************
*** Source and Adapter ***
**********************var stateSource = {
datatype: “json”,
datafields: [
{ name: ‘ID’ },
{ name: ‘State’ }
],
id: ‘id’,
url: ‘StateJSON.php’,
async: false
};var stateDataAdapter = new $.jqx.dataAdapter(stateSource, {
autoBind: true,
beforeLoadComplete: function (records) {
var data = new Array();
for (var i = 0; i prepare(“SELECT column_name name, LEFT(column_type,INSTR(column_type, ‘(‘)-1) type, substr(column_type, INSTR(column_type, ‘(‘)+1, (INSTR(column_type, ‘)’))-(INSTR(column_type, ‘(‘)+1)) size FROM information_schema.columns WHERE table_name=? AND column_name=?”);
$preparedStatement->bindParam(1, $table, PDO::PARAM_STR);
$preparedStatement->bindParam(2, $column, PDO::PARAM_STR);
if ($preparedStatement->execute()) {
$preparedStatement->bindColumn(“name”, $name);
$preparedStatement->bindColumn(“type”, $type);
$preparedStatement->bindColumn(“size”, $size);
while ($row = $preparedStatement->fetch(PDO::FETCH_BOUND)) {
if ($type === “int”) {
updateColumnINT($conn, $table, $updated, $updatedBy, $id, $column, $value, $name, $type, $size);
} else if ($type === “varchar”) {
updateColumnVARCHAR($conn, $table, $updated, $updatedBy, $id, $column, $value, $name, $type, $size);
} else if ($type === “date”) {
updateColumnVARCHAR($conn, $table, $updated, $updatedBy, $id, $column, $value, $name, $type, $size);
} else {
die(“Type unknown! $type”);
}
}
} else {
echo “MetaData Failed! “;
}
}function updateColumnINT($conn, $table, $updated, $updatedBy, $id, $column, $value, $name, $type, $size) {
$preparedStatement = $conn->prepare(“UPDATE $table set $column=?, Updated=?, UpdatedBy=? WHERE id=?”);
$preparedStatement->bindParam(1, $value, PDO::PARAM_INT);
$preparedStatement->bindParam(2, $updated, PDO::PARAM_STR);
$preparedStatement->bindParam(3, $updatedby, PDO::PARAM_STR);
$preparedStatement->bindParam(4, $id, PDO::PARAM_INT);
if ($preparedStatement->execute()) {
echo “$column = $value Updated Successfully!”;
} else {
echo “PreparedStatement Failed!”;
}
}function updateColumnVARCHAR($conn, $table, $updated, $updatedBy, $id, $column, $value, $name, $type, $size) {
$preparedStatement = $conn->prepare(“UPDATE $table set $column=?, Updated=?, UpdatedBy=? WHERE id=?”);
$preparedStatement->bindParam(1, $value, PDO::PARAM_STR);
$preparedStatement->bindParam(2, $updated, PDO::PARAM_STR);
$preparedStatement->bindParam(3, $updatedby, PDO::PARAM_STR);
$preparedStatement->bindParam(4, $id, PDO::PARAM_INT);
if ($preparedStatement->execute()) {
echo “$column = $value Updated Successfully!”;
} else {
echo “PreparedStatement Failed!”;
}
}function updateColumnDate($conn, $table, $updated, $updatedBy, $id, $column, $value, $name, $type, $size) {
$preparedStatement = $conn->prepare(“UPDATE $table set $column=?, Updated=?, UpdatedBy=? WHERE id=?”);
$preparedStatement->bindParam(1, $value, PDO::PARAM_STR);
$preparedStatement->bindParam(2, $updated, PDO::PARAM_STR);
$preparedStatement->bindParam(3, $updatedby, PDO::PARAM_STR);
$preparedStatement->bindParam(4, $id, PDO::PARAM_INT);
if ($preparedStatement->execute()) {
echo “$column = $value Updated Successfully!”;
} else {
echo “PreparedStatement Failed!”;
}
}Hi David,
I suggest you to take a look at the ComboBox’s Binding to JSON demo: bindingtojson.htm. If you have the item’s index, you can get the item’s label and value, too.
Example:
$("#jqxWidget").bind('select', function (event) { if (event.args) { var item = event.args.item; if (item) { var value = item.value; var label = item.label; } }
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.