jQuery UI Widgets › Forums › Editors › DateTimeInput › Problem updating Date and Bool with jqwidget.
Tagged: checkbox, datetimeinput, jquery grid, json
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 11 years, 6 months ago.
-
Author
-
Hi everyone,
I’m a beginner with jqwidget and it’s been a long time since I wrote my last line of code so I hope you won’t find my question stupid.
So, I have a grid with different datatype coming from a mysql database. Data are parsed with json. When I try to update string, it works but I can’t update Date (using the calendar) and bool (using checkbox).
Here is my configuration:
Index.php File
————————-
<script type=”text/javascript”>
$(document).ready(function () {
// prepare the data
var data = {};
var theme = ‘classic’;var source =
{
datatype: “json”,
datafields: [
{ name: ‘Contact_ID’, type: ‘string’},
{ name: ‘First_Name’, type: ‘string’},
{ name: ‘Last_Name’, type: ‘string’},
{ name: ‘Phone’, type: ‘string’},
{ name: ‘Email’, type: ‘string’},
{ name: ‘Contact_Date’, type: ‘date’, formatString: ‘D’},
{ name: ‘Preferred_Contact_Method’, type: ‘string’},
{ name: ‘Comments’, type: ‘string’},
{ name: ‘Status’, type: ‘string’},
{ name: ‘Active’, type: ‘bool’}
],
cache: false,
id: ‘Contact_ID’,
url: ‘data.php’,
updaterow: function (rowid, rowdata, commit) {
// synchronize with the server – send update command
var data = “update=true&First_Name=” + rowdata.First_Name + “&Last_Name=” + rowdata.Last_Name;
data = data + “&Phone=” + rowdata.Phone + “&Email=” + rowdata.Email + “&Contact_Date=” + rowdata.Contact_Date + “&Preferred_Contact_Method=” + rowdata.Preferred_Contact_Method + “&Comments=” + rowdata.Comments + “&Status=” + rowdata.Status + “&Active=” + rowdata.Active;
data = data + “&Contact_ID=” + rowdata.Contact_ID;$.ajax({
dataType: ‘json’,
url: ‘data.php’,
data: data,
success: function (data, status, xhr) {
// update command is executed.
commit(true);
}
});
}
};var dataAdapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$(“#jqxgrid”).jqxGrid(
{
width: 1200,
height: 450,
selectionmode: ‘singlecell’,
source: dataAdapter,
theme: theme,
editable: true,
columns: [
{ text: ‘Contact ID’, editable: false, datafield: ‘Contact_ID’, width: 80 },
{ text: ‘First Name’, datafield: ‘First_Name’, width: 100 },
{ text: ‘Last Name’, datafield: ‘Last_Name’, width: 100 },
{ text: ‘Phone’, datafield: ‘Phone’, width: 120 },
{ text: ‘Email’, datafield: ‘Email’, width: 150 },
{ text: ‘Contact Date’, columntype: ‘datetimeinput’, cellsformat: ‘MM-dd-yy’, datafield: ‘Contact_Date’, width: 150 },
{ text: ‘Preferred Contact’, columntype: ‘dropdownlist’, datafield: ‘Preferred_Contact_Method’, width: 100 },
{ text: ‘Comments’, datafield: ‘Comments’, width: 150 },
{ text: ‘Status’, columntype: ‘dropdownlist’, datafield: ‘Status’, width: 100 },
{ text: ‘Active’, columntype: ‘checkbox’, datafield: ‘Active’, width: 100 }
]
});
});
</script>————————-
Data.php FILE
————————-
// get data and store in a json array
$query = “SELECT * FROM Contacts”;if (isset($_GET[‘update’]))
{
// UPDATE COMMAND
$update_query = “UPDATE `Contacts` SET
`First_Name`='”.$_GET[‘First_Name’].”‘,
`Last_Name`='”.$_GET[‘Last_Name’].”‘,
`Phone`='”.$_GET[‘Phone’].”‘,
`Email`='”.$_GET[‘Email’].”‘,
`Contact_Date`='”.$_GET[‘Contact_Date’].”‘,
`Preferred_Contact_Method`='”.$_GET[‘Preferred_Contact_Method’].”‘,
`Comments`='”.$_GET[‘Comments’].”‘,
`Status`='”.$_GET[‘Status’].”‘,
`Active`='”.$_GET[‘Active’].”‘
WHERE `Contact_ID`='”.$_GET[‘Contact_ID’].”‘”;
$result = mysql_query($update_query) or die(“SQL Error 1: ” . mysql_error());
echo $result;
}————————-
In database,
Date is set as “Date”
Active is set a tinyint.
Thanks a lot for your help.
Hi yabenjo,
What is the value of rowdata.Active and rowdata.Contact_Date when the “updaterow” callback is called? In general, dates in jqxGrid are stored as JavaScript Date Objects, not with the formatted String displayed in the Cell. So if you wish to get the cell’s value of the “Contact_Date”, you can do the following:
var contactDateText = $("#jqxgrid").jqxGrid('getcelltextbyid', rowid, 'Contact_Date');
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.