datatables jeditable validate input url how to combine this code? - validation

I'm using datatables with the jeditable plugin, I have it setup to update directly to mysql, I need to validate some input fields to make sure a URL is being inserted. I have this code which validates jeditable fields (see jsfiddle) I need some help to integrate the jsfiddle with the table initializing code. I can add the onsubmit no problem but not sure how to add this part into my .makeEditable function, any help's appreciated thanks.
$('#url').editable(function(valurl) {
// Do your own stuff here...
return valurl;
},
http://jsfiddle.net/peter/CLuvp/
And my datatable is initialized with
var oTable3;
$(document).ready(function() {
oTable3 = $('#table3').dataTable( {
"sDom":'t<"bottom"ifpl><"clear">',
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "bSortable": false},
null,
null,
null,
null
]
}
).makeEditable({
sUpdateURL: "<?=$this->siteUrl()?>profiles/updatevalue",
"aoColumns": [null,
null,
{
type: 'text',
submit:'Ok',
cancel:'Cancel',
width: "100px"
}

I think you can simply include the options for each column in the aoColumns option, e.g.:
.makeEditable({
sUpdateURL: "<?=$this->siteUrl()?>profiles/updatevalue",
"aoColumns": [null, null,
{
submit: 'Save',
width: 200,
placeholder: 'Enter URL...',
onblur: 'submit',
onsubmit: function() {...}
}]
});
A cleaner way (or the aforementioned simply doesn't work) would be to use the url rule in that column:
.makeEditable({
sUpdateURL: "<?=$this->siteUrl()?>profiles/updatevalue",
"aoColumns": [null, null,
{
submit: 'Save',
width: 200,
placeholder: 'Enter URL...',
onblur: 'submit',
cssclass: 'url'
}]
});
See this demo for more details.

Related

Datatable column onClick

I am referring the following Datatable example -
https://datatables.net/examples/api/select_single_row.html
The example captures onclick event on the entire row
$('#example tbody').on( 'click', 'tr', function (){}
I wish to capture an event on the click of a particular columns,
say column Name, Position and Office.
How do I do that?
If you know the table colums index then you might you use this.
$('#example tbody').on( 'click', 'tr td:eq(0)', function (){
alert("col1");
});
$('#example tbody').on( 'click', 'tr td:eq(1)', function (){
alert("col2");
});
$('#example tbody').on( 'click', 'tr td:eq(4)', function (){
alert("col5");
});
You can access clicks in columns hooking and event handler in the elements you want in the fnRowCallback.
Here is a complete example with a table with 2 extra columns showing an icon that receives the click:
$('#example').DataTable({
dom: 'lfrt',
paging: false,
rowBorder: true,
hover: true,
serverSide: false,
rowHeight: 30,
order: [[ 1, 'asc' ]],
columns: [
{
title: 'Id',
visible: false,
searchable: false
},
{
title: 'version',
visible: false,
searchable: false
} {
title: Name'
},
{
data: null,
title: 'Diagram',
searchable: false,
sortable: false,
defaultContent: '<i class="fa fa fa-sitemap icon-btn" data-btnaction="grafo"></i>',
className: 'text-center'
},
{
data: null,
title: 'History',
searchable: false,
sortable: false,
defaultContent: '<i class="fa fa-history icon-btn" data-btnaction="appdetail"></i>',
className: 'text-center'
}
],
select: false,
fnRowCallback: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$('td > i', nRow).on('click', function() {
// if you have the property "data" in your columns, access via aData.property_name
// if not, access data array from parameter aData, aData[0] = data for field 0, and so on...
var btnAction = $(this).data('btnaction');
if (btnAction === 'grafo'){
} else if (btnAction === 'appdetail'){
// do something......
}
});
}
});

validate jqgrid data on the server, callback function

I am using autocomplete in a textbox on my jqgrid. But i should not allow the user to select the same item twice. Because of pagination he wont see all data all times. Is there a way that on sending new row to server check for duplicate data in the server and send a status back to jqgrid maybe poping up an alert sayign "row already exist on table". What would be the bst approach to do this validation and notify the user? thanks.
$("#assessmentproduct").jqGrid({
url: 'orthofixServices.asmx/GetProductList',
colNames: ['id', 'Product Description', 'Commission Rate'],
colModel: [
{ name: 'id', hidden: true },
{ name: 'description', index: 'desc', width: 320, editable: true },
{ name: 'commissionrate', index: 'com', width: 120, editable: true, unformat: percentUnFormatter, formatter: percentFormatter, editrules: { number: true} }
],
serializeRowData: function(data) {
var params = new Object();
params.id = 0;
params.prdid = $("#prdid").val();
params.description = data.description;
params.commissionrate = data.commissionrate;
var result = JSON.stringify({ 'passformvalue': params, 'oper': data.oper, 'id': data.id });
return result;
},
mtype: "POST",
rowNum: 4,
height: 93,
width: 400,
pager: '#assessmentpager',
editurl: "orthofixServices.asmx/ModifyProductList"
});
$("#assessmentproduct").jqGrid('navGrid', '#assessmentpager', { add: false, edit: false, del: true, refresh: false, search: false }, {}, {}, { serializeDelData: function(postData) {
return JSON.stringify({ 'passformvalue': null, 'oper': postData.oper, 'id': postData.id });
}
});
$("#assessmentproduct").jqGrid('inlineNav', '#assessmentpager', { addParams: { position: "last", addRowParams: {
"errorfunc": duplicateRow, "aftersavefunc": function() { var grid = $("#assessmentproduct"); reloadgrid(grid); }
}
}, editParams: { "aftersavefunc": function() { var grid = $("#assessmentproduct"); reloadgrid(grid); } }
});
You should just hold the simple rule: if an error occur on the server (for example because of validation error) the server response should contains some error HTTP status code. In the case error message will be displayed to the user.
The exact error processing and the displayed error message format depends from the editing mode which you use. In case of inline editing I would recommend you to use errorfunc and restoreAfterError parameters of the editRow method. In case of form editing the errorTextFormat callback can be very helpful.

Jqgrid on Edit operation sends "add" as oper="add" why?

I have a weird one. After changing the data store from session to oracle, when i hit Edit on the 'inlineNav' it always goes to the server with the "add" operation. Any ideas why this could happened?
$("#assessmentproduct").jqGrid({
url: 'orthofixServices.asmx/GetProductList',
colNames: ['id', 'Product Description', 'Commission Rate'],
colModel: [
{ name: 'id' },
{ name: 'description', index: 'desc', width: 170, editable: true },
{ name: 'commissionrate', index: 'com', width: 80, editable: true, unformat: percentUnFormatter, formatter: percentFormatter, editrules: { number: true} }
],
serializeRowData: function(data) {
var params = new Object();
params.id = 0;
params.prdid = parseInt($("#prdid").val());
params.description = data.description;
params.commissionrate = data.commissionrate;
return JSON.stringify({ 'passformvalue': params, 'oper': data.oper, 'id': data.id });
},
mtype: "POST",
rowNum: 4,
height: 93,
width: 400,
pager: '#assessmentpager',
editurl: "orthofixServices.asmx/ModifyProductList"
});
$("#assessmentproduct").jqGrid('navGrid', '#assessmentpager', { add: false, edit: false, del: true, refresh: false, search: false }, {}, {}, { serializeDelData: function(postData) {
return JSON.stringify({ 'passformvalue': null, 'oper': postData.oper, 'id': postData.id });
}
});
$("#assessmentproduct").jqGrid('inlineNav', '#assessmentpager', { addParams: { position: "last", addRowParams: {
"aftersavefunc": function() { var grid = $("#assessmentproduct"); reloadgrid(grid); }
}
}, editParams: { "aftersavefunc": function() { var grid = $("#assessmentproduct"); reloadgrid(grid); } }
});
You use JSON.stringify inside of serializeRowData to serialize the posted data to JSON. It's the reason of the encoding which you describe.
UPDATED: OK! Now I see at the end what's the problem. The reason of the misunderstanding was because you used oper="add" in the title instead of oper=add. I understood you that this is your problem (sending of quoted oper="add" instead of oper=add). OK. The problem with sending of oper=add in case of edit operation is known jqGrid bug which is already fixed in the code on the github (see here). You can make the same changes in jquery.jqGrid.src.js and use the fixed code till the new version of jqGrid will released.

jqgrid inline searching

I have a jqgrid that I am performing an inline edit on. I am using the textarea instead of text. How do I submit the data once I'm done editing the cell. "Enter" works on text and obviously doesn't on textarea since it creates a new line.
This is a snippet from my code
grid4 = $('#CaseNotes').jqGrid({
...
{ name: 'Note', index: 'Note', width: 650, align: 'left', sortable: false,
editable: true, edittype: 'textarea', editoptions: { rows: '5', cols: '100' }
},
...
onSelectRow: function (id) {
if (id && id != lastsel) {
grid4.restoreRow(lastsel);
lastsel = id;
}
grid4.jqGrid('editRow', id, true, '', '', '', '', reload);
},
editurl: '#Url.Action("EditCaseNote", "CaseNote")',
...
});
//function to reload the grid
function reload(id, result) {
grid4.setGridParam(
{
url: '#Url.Action("DisplayCaseNotesGrid", "CaseInfo")',
datatype: 'json'
}
).trigger('reloadGrid');
}
If I understand you correct you mean "inline editing" instead of "inline searching". Because you can't use Enter key you have to include some additional button in the Navigator toolbar which call saveRow method. You can either add the corresponding row manually with respect of navButtonAdd or use inlineNav method.
Thanks to Oleg's advise I was able to solve this. Here is my code incase anyone runs into a similar problem. I removed my refresh function since I no longer needed it.
grid4 = $('#CaseNotes').jqGrid({
...
{ name: 'Note', index: 'Note', width: 650, align: 'left', sortable: false,
editable: true, edittype: 'textarea', editoptions: { rows: '5', cols: '100' }
},
...
onSelectRow: function (id) {
if (id && id != lastsel) {
grid4.restoreRow(lastsel);
lastsel = id;
}
grid4.jqGrid('editRow', id, { keys: true, afterrestorefunc: reload });
},
...
});
//Adds the button to the pager
grid4.jqGrid('navButtonAdd', '#casenotes_pager', {
caption: 'Save Case Note',
buttonicon: 'none',
onClickButton: function () {
//calls the saveRow function
grid4.jqGrid('saveRow', lastsel,
{
url: '#Url.Action("EditCaseNote", "CaseNote")'
}
);
//refreshes the grid
grid4.setGridParam(
{
url: '#Url.Action("DisplayCaseNotesGrid", "CaseInfo")',
datatype: 'json'
}
).trigger('reloadGrid');
}
});

Unable to sort data in ExtJS DataGrid when grouped

I'm using ExtJS 3.3.0 with a datagrid that consumes a JSON data store (Ext.data.GroupingStore).
When I'm not grouping by a column, I can sort just fine, however when grouping by a column, the sort algorithm seems to fall apart.
I have another data grid that does server side sorting (and grouping and paging) and this works just fine. Comparing the the code between the two has left me stumped for the difference that's making one work and the other not work.
Many thanks in advance.
CW.App.FileGrid = {
store : null,
initComponent: function(){
this.store = new Ext.data.GroupingStore({
autoLoad:true,
url:'/sites/files.js',
groupField:'modified',
// Sort by whatever field was just grouped by. This makes the data
// make more sense to the user.
groupOnSort:true,
remoteSort:false,
remoteGroup:false,
sortInfo:{
field:'modified',
direction:'DESC'
},
reader: new Ext.data.JsonReader({
idProperty:'filename',
root:'data',
fields: [
'iconCls',
{
name: 'modified',
type: 'date',
dateFormat:'timestamp'
},
'description', 'folder', 'filename',
'filesize', 'ext', 'dateGroup']
})
});
// this.store.setDefaultSort('modified', 'DESC');
Ext.apply(this, {
store: this.store,
loadMask:true,
columns: [
{
xtype:'actioncolumn',
items:[{
getClass:function(v,meta,rec){
return rec.get('iconCls');
}
}],
width:25
},{
id:'filename',
header: "Filename",
sortable: true,
dataIndex: 'filename'
},{
id:'ibmu',
header: "iBMU",
width:50,
sortable:true,
dataIndex: 'folder'
},{
id:'date',
header: "Date",
width: 65,
sortable: true,
dataIndex: 'modified',
renderer: Ext.util.Format.dateRenderer('Y-m-d h:i'),
groupRenderer:function(v,unused,r,rowIdx,colIdx,ds){
return r.data['dateGroup'];
}
},{
id:'type',
header: "Type",
width: 70,
sortable: true,
dataIndex: 'description'
},{
id:'size',
header: "Size",
width: 50,
sortable: true,
dataIndex: 'filesize',
renderer: Ext.util.Format.fileSize
},{
xtype:'actioncolumn',
items:[{
icon: '/img/fam/drive_disk.png',
tooltip: 'Download file',
handler: function(grid, rowIndex, colIndex){
var rec = store.getAt(rowIndex);
location.href = Ext.urlAppend('/ibmus/download/', Ext.urlEncode({
folder: rec.get('folder'),
filename: rec.get('filename')
}));
}
}]
}
],
autoExpandColumn:'filename',
view: new Ext.grid.GroupingView({
emptyText: 'No files found. Please wait up to 24 hours after activating your account for files to appear.',
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Files" : "File"]})'
}),
frame:false,
width: '100%',
height: 250,
collapsible: false,
animCollapse: false
});
CW.App.AlarmGrid.superclass.initComponent.call(this);
}
};

Resources