I have a custom button for my jqgrid that when pressed takes me to another view.
But for some reason when i navigate between the tabs there is an extra added custom button every time a re-visit that tab. Is there a way to say only to add this button once?
This is the markup:
$('#tabs').tabs( {
show: function (event, ui) {
if(ui.index == 0) {
Show some content on this tab.. Not important.
}
if(ui.index == 1) {
$("#functionslist").jqGrid({
datatype: 'json',
url: '/Admin/GetFunctionsList',
colNames: ['Namn'],
colModel: [
{ index: 'FunctionName',
name: 'FunctionName',
width: 100,
sortable: false
}
],
rowNum: 20,
prmNames: { sort: 'SortColumn', order: 'SortOrder', page: 'Page', rows: 'Rows', search: null, nd: null },
hidegrid: false,
pager: '#functionspager',
autowidth: true,
shrinkToFit: true,
height: '100%',
caption: 'Functions',
viewrecords: true,
onSelectRow: function (id) {
window.location.href = '/Function/Edit/' + id;
}
}).jqGrid('navGrid', '#functionspager', { edit: false, add: false, del: false, search: false, refresh: false })
.navButtonAdd('#functionspager', {
caption: '',
title: 'Create new function',
buttonicon: 'ui-icon-plus',
onClickButton: function () {
window.location = '/Function/Add/';
}
}); .... and so forth....
Everything runs fine and i have the behavior i desire but for some reason when i navigate between the two tabs more and more custom button are added. Any ideas why, have tried to resolve this but with no luck.
/Daniel
Why not check to see if the button already exists before adding it?
if ($('#functionspager :has(".ui-icon-plus")').length == 0) {
$("#functionslist").jqGrid('navGrid', '#functionspager', { edit: false, add: false, del: false, search: false, refresh: false })
.navButtonAdd('#functionspager', {
...
});
}
The call $("#functionslist").jqGrid({/*parameters*/); convert the empty <table> to a grid having columns, capture, pager and so on. You should make the call once and not repeat it on every tab activation.
Exactly in the same way the methods navGrid and navButtonAdd should be called only once.
So you should decide what should be done if the user select the tab having jqGrid. You can for example call
$("#functionslist").trigger('reloadGrid', [{current:true}]);
(see here for details)
Related
I'm trying to retrieve a list of events from an ajax call. I use the following code.
document.addEventListener("DOMContentLoaded", function()
{ var calendarEl = document.getElementById("id_d_agenda_1");
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
defaultDate: '2019-08-12',
editable: true,
navLinks: true, // can click day/week names to navigate views
eventLimit: true, // allow "more" link when too many events
selectMirror: true,
select: function(arg) {
var title = prompt('Event Title:');
if (title) {
calendar.addEvent({
title: title,
start: arg.start,
end: arg.end,
allDay: arg.allDay
})
}
calendar.unselect()
},
events: function(arg) {
$.ajax({
url: 'd.php',
dataType: 'json',
data: {
cmd:'getdata',
start:arg.startStr,
end:arg.endStr,
tz:arg.timeZone,
component:'d_agenda_1',
},
success: function(doc) {
$(doc).each(function() {
calendar.addEvent( this );
})
}
})
}
})
calendar.render();
});
While debugging my javascript I can see the rows of events appear in 'doc'. First I tried to bulk add them to the agenda, but that didn't seem to work. Now I'm adding them one-by-one, buth they still don't appear. I have checked the this variable in the debugger and it shows a single event:
title:"value", start:"2019-08-01". In fact I'm using the sample list that comes with the package. Can someone point me to the right direction in what I'm doing wrong?
other options I tried (with no luck ;-):
I tried to leave the jquery out, but with similar effect:
success: function(doc) {
doc.forEach(function(value) {
calendar.addEvent( value );
})
}
success: function(doc) {
$(doc).each(function() {
calendar.addEvent({
title:this.title,
start:this.start
});
})
Not sure if it's helpful, but I added the selectable option and tested the select option. The calendar.addevent on the select: doesn't add the event either. Since this is copied from the sample i'm quite confused now. Fun part is that if you replace the ajax part with a regular [] expression that all works well. Even the selectable options, so there's definitely something wrong with my ajax implementation, in regards to this component.
According to the DOCS you need to have a successCallback that will return the events to the calendar.
Here is the docs https://fullcalendar.io/docs/events-function
Here is a simple Demo https://codepen.io/nasser-ali-karimi/pen/gOOJrWV?editors=0010
And in short, I can say that you need to set the events like this.
events: function(info, successCallback, failureCallback) {
successCallback([
{"resourceId":"a","title":"event 1","start":"2019-11-23","end":"2019-11-25"},
{"resourceId":"b","title":"event 3","start":"2019-11-24T12:00","end":"2019-11-25T06:00"},
{"resourceId":"b","title":"event 4","start":"2019-11-24T07:30","end":"2019-11-24T09:30"},
{"resourceId":"b","title":"event 5","start":"2019-11-24T10:00","end":"2019-11-24T15:00"},
{"resourceId":"a","title":"event 2","start":"2019-11-24T09:00","end":"2019-11-24T14:00"}
])
}
you didn't mention the events data that comes from Ajax request, so I can say you need to provide the data like what said on docs.
Addition
Note: Event's date are on 11/28 and 11,29 so navigate to those dates to see the events.
Demo https://codepen.io/nasser-ali-karimi/pen/qBBGVbG?editors=0010
events: function(info, successCallback, failureCallback) {
var arrevents = [];
jQuery.get( "https://api.myjson.com/bins/16ubhe", function( data ) {
// var response = JSON.parse(data);
// $.each(response, function(k, v) {
// arrevents.push(v);
// });
arrevents = data;
successCallback(arrevents);
});
},
I am using jqGrid v 5.1.0 using the Bootstrap style. When I apply ui-state-disabled class to a pager button (add) the button looks disabled but when clicked it still processes the event. In previous version this use to disable the event as well. Using latest FF and IE. Any ideas? Thank you.
Edit - add snippet of code that initializes the grid (child). Notice second line from end where the add button is disabled. The button appears disabled but when clicked the event is executed.
Edit 2 - So after much pain and tears I create two fiddles. One demonstrates proper disabling of the edit button and Two is the same code but using Bootstrap. The edit button is not disabled.
// Water Source grid options...
var source_gridOptions = {
caption: 'Associated Water Source(s)',
data: sourceData,
datatype: 'local',
//url: "", // updated dynamically
//mtype: "GET",
styleUI : 'Bootstrap',
colModel: [
{ label: 'Source ID', name: 'ID', key: true, width: 28 },
{ label: 'Case ID', name: 'WATER_CASE_ID', width: 28, hidden: true },
{ label: 'Intake Name', name: 'INTAKE_SOURCE_NAME', width: 50 },
{ label: 'Intake Type', name: 'INTAKE_SOURCE_TYPE', width: 30 },
{ label: 'Source Type', name: 'SOURCE_TYPE', width: 20 },
{ label: 'Water Type', name: 'WATER_TYPE', width: 20 },
{ label: 'Notes', name: 'NOTES', width: 50 },
{ label: 'Verified', name: 'VERIFIED', width: 25 },
],
viewrecords: true,
height: 'auto',
width: initTabWidth, //dynamically set...
rowNum: 5,
pager: "#sourcePager",
gridComplete: function() {
} // end grid complete event
};
// define CRUD options...
var source_editOptions = {};
var source_addOptions = {};
var source_deleteOptions = {};
// init Water Source grid...
$("#sourceGrid").jqGrid(source_gridOptions).navGrid("#sourcePager",{edit:true,add:true,del:true,search:false},source_editOptions,source_addOptions,source_deleteOptions);
$("#add_sourceGrid").addClass('ui-state-disabled'); // <-- disable button
}); // end grid
Given your demo, I was able to figure it out. You actually need to add the ui-disabled class to work, not just disabled that you've added.
I've modified your fiddle here: http://jsfiddle.net/c6860ev8/16/
You can see in the jqGrid source file which classes are required for bootstrap integration here: https://github.com/tonytomov/jqGrid/blob/7901d7b7da969de1ca98282c60e335e013dc31ee/js/grid.base.js#L1035
Hope this helps!
I have this code, no API nor nothing, I simply would like to get a Group ID inside here for it to be the default option for where to share the comment and embed the comment stream on Yammer, is this even possible? Is there a way to block the possibility of selection from all your groups and leave it to just one?
<script>
yam.connect.embedFeed({
container: "#embedded-feed",
feedType: "open-graph",
config: {
header: true,
footer: false,
promptText: "Remember to select a Group and/or person",
showOpenGraphPreview: true,
}
});
</script>
The Code is working, but I just need to filter that option
Thank you
We just released this feature. Documentation is to be updated very soon, use "defaultGroupId" inside your config to get your group selected.
i have done a simple implementation like this.
var generateYammerFeeds = function(title, description) {
try {
yam.connect.embedFeed({
container: "#yammerDiscussion",
network: "abc.com",
feedType: "open-graph",
objectProperties: {
fetch: true,
private: false,
ignore_canonical_url: false,
url: location.href,
type: "page",
title: title,
image: '',
description: description
},
config: {
header: true,
footer: true,
showOpenGraphPreview: false,
defaultToCanonical: true,
hideNetworkName: true,
promptText: "Ask a Question",
defaultGroupId: 121212
}
});
return true;
} catch (e) {
return null;
}
};
I'm a newbie of extjs (using ext.js 4.1),I'm still learning it, but the thing that I have to do now is a little tricky and I would like to have the advice of a more experienced developer. The problem is regarding these buttons:
{
xtype : 'checkboxgroup',
store : checked,
columns : 3,
vertical : false,
singleSelect: true,
items : [
{
xtype: 'button',
text: 'name',
width: 75,
toggleGroup: 'mygroup',
enableToggle: true
}, {
xtype: 'button',
text: 'email',
width:75,
toggleGroup: 'mygroup',
enableToggle: true
}, {
xtype: 'button',
text: 'id',
width: 75,
toggleGroup: 'mygroup',
enableToggle: true
}
],
listeners :
{
'change' :
// store checked field
function(th, newValue, oldValue) {
var ics = th.items.items;
for (i = 0; i < 3; i++) {
checked[i] = ics[i].checked;
}
}
}
}
As you can see there is a listener, it was working when the buttons were only checkboxes (i'm changing them now to be checked only one at time). Now I assume I have to change the listener to many more listeners, one for each button. But the questions are:
How do i get the value from the buttons?
How should the function of the listener be structured at the level of the parameters of the function?
I will have to change the "checked" variable which filters the store...
I'm copying from this answer, but it doesn't work still. It doesn't register the event.
Adding a listener to a button is quite simple. It is binding the botton with the function outside it that is difficult. However the listener for the button is found:
{
xtype: 'button',
text: 'name',
width: 75,
toggleGroup: 'mygroup',
enableToggle: true,
listeners: {
click: function() {
//this == the button, as we are in the local scope
this.setText('I was clicked!');
}}
}
jqGrid pass value to form editing
as a follow-up question to this... I have a grid with one cell as a checkbox and form editing. I was able to load value of cell using this solution, however on submit it is passing back everything inside formatter quotes and throwing a server error. How can I pass back just the value 1:0?
Line from grid...
{ name: 'NS', index: 'NS', width: 20, editable: true, hidden: false, edittype: 'checkbox', editrules: { edithidden: true, required: true }, formoptions: { rowpos: 11}, formatter: checkTrue }
Formatter used...
formatter: function (cellvalue, options, rowdata) {
if (cellvalue == 0) {
return "<span class=\"ui-icon ui-icon-close\">0</span>";
} else {
return "<span class=\"ui-icon ui-icon-check\">1</span>";
}
}
You can use an unformatter
{ name: 'NS', index: 'NS', width: 20, editable: true, hidden: false, edittype: 'checkbox', editrules: { edithidden: true, required: true }, formoptions: { rowpos: 11}, formatter: checkTrue, unformat: unFormat }
function unFormat( cellvalue, options, cell){
return $('span', cell).text();
}
An unformatter takes the following parameters:
cellvalue - the value to be unformatted.
options - An object that contains the row id and column model
cellobject - A JQuery cell object.