Save "
+ $("
is null ? Save "
+ "Cancel
")
.appendTo($wrapper);
+ // Bind dom click events to respective functions
+ $wrapper.find(".allow_null_input").bind("click", this.mark_null);
$wrapper.find("button:first").bind("click", this.save);
$wrapper.find("button:last").bind("click", this.cancel);
$input.bind("keydown", this.handleKeyDown);
@@ -47,6 +49,19 @@
$input.focus().select();
};
+ // Toggle checkbox - Set/Unset editor value to default and Null
+ this.mark_null = function() {
+ var is_null = $(this).find('input[type="checkbox"]').is(':checked');
+ if (is_null) {
+ $input.val("null");
+ }
+ else {
+ $input.val(row_value);
+ }
+ $input.attr('readonly', is_null);
+ args.column.is_null = is_null;
+ };
+
this.handleKeyDown = function (e) {
if (e.which == $.ui.keyCode.ENTER && e.ctrlKey) {
scope.save();
@@ -107,8 +122,19 @@
};
this.loadValue = function (item) {
- $input.val(defaultValue = item[args.column.field]);
- $input.select();
+ // If cell value is null, mark checkbox selected.
+ // And set editor value to "Null" text
+ if (item[args.column.field] === null) {
+ $input.parent().find('input[type="checkbox"]')
+ .attr('checked', true);
+ $input.val('null').attr('readonly', true);
+ row_value = "";
+ }
+ else {
+ $input.val(defaultValue = item[args.column.field]);
+ $input.select();
+ row_value = $input.val();
+ }
};
this.serializeValue = function () {
diff --git a/web/pgadmin/tools/sqleditor/static/css/sqleditor.css b/web/pgadmin/tools/sqleditor/static/css/sqleditor.css
index f22963b..4b1aab2 100644
--- a/web/pgadmin/tools/sqleditor/static/css/sqleditor.css
+++ b/web/pgadmin/tools/sqleditor/static/css/sqleditor.css
@@ -435,4 +435,16 @@ input.editor-checkbox {
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
-ms-box-sizing: content-box;
-}
\ No newline at end of file
+}
+
+/* Container class for "is_null" checkbox & label*/
+.allow_null_input label {
+ padding-left: 5px;
+ font-weight: normal;
+}
+
+/* Set background color for disabled pgEditor */
+.pg_custom_editor[readonly] {
+ background: #EEEEEE;
+ font-style: italic;
+}
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
index 453453b..a43faec 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
@@ -593,6 +593,9 @@ define(
} else {
options['editor'] = is_editable ? Slick.Editors.pgText
: Slick.Editors.ReadOnlypgText;
+ // Add option "is_null" in column info to
+ // keep track of "Null" type values.
+ options['is_null'] = false;
}
grid_columns.push(options)
@@ -754,10 +757,17 @@ define(
grid.onCellChange.subscribe(function (e, args) {
// self.handler.data_store.updated will holds all the updated data
var changed_column = args.grid.getColumns()[args.cell].field, // Current filed name
- updated_data = args.item[changed_column], // New value for current field
_pk = args.item.__temp_PK || null, // Unique key to identify row
column_data = {},
_type;
+ // Set column value to "null" if flag "is_null" is set to true.
+ if (!_.isUndefined(args.grid.getColumns()[args.cell].is_null)
+ && args.grid.getColumns()[args.cell].is_null) {
+ updated_data = null;
+ }
+ else {
+ updated_data = args.item[changed_column]; // New value for current field
+ }
column_data[changed_column] = updated_data;