Kendo UI adding row at Runtime(Client Side) - grid

I am able to add a row at runtime using .js file into Kendo Data Source, but I havent seen from the form(UI), I followed the below steps
var vgrid = $("#grdEntitys").data("kendoGrid");
var datasource = vgrid.dataSource;
var newRecord = { No: "8164",ModellNo: "147",ID: "Test01", Name: "TEST"}
datasource.insert(newRecord);
then It throws an error "TypeError: Cannot read property 'AttributeValue' of undefined",
if we look at the console log, I am able to see the incrmented rows count as well as the newly inserted record. But in UI there is no change(UI Grid).
could you please anyone let me know, how to add row at client side?
Thanks in advance

For insert you have to specify index (Insert) :
var dataItem = dataSource.insert(0, { name: "John Doe" });
Alternatively you could use Add where you don't have to specify the index:
<script>
var dataSource= new kendo.data.DataSource({
data: [
{ name: "Jane Doe", age: 30 }
]
});
dataSource.add({ name: "John Doe", age: 33 });

you can use the script in you event to add item in your grid.
var dataSource = $("#CustomerPackageChannelKendoGridAdd").data("kendoGrid").dataSource;
// Get value from another field
var _JV_ACCOUNT_ID = $('#JV_ACCOUNT_ID').val();
var _JV_ACCOUNT_NAME = $('#JV_ACCOUNT_NAME').val();
var _JV_ACCOUNT_CODE = $('#JV_ACCOUNT_CODE').val();
var _JV_NOTES = $('#JV_NOTES').val();
var _JV_DATE = $('#JV_DATE').val();
var type = $('#JV_Transaction_TYPE').val();
// You can set condition if required for you
if (CheckExistingData(gridDataAdd, _JV_ACCOUNT_ID) == false) {
currentId += 1;
dataSource.add(
{
id: currentId,
JV_ACCOUNT_ID: _JV_ACCOUNT_ID,
JV_ACCOUNT_NAME: _JV_ACCOUNT_NAME
, JV_ACCOUNT_CODE: _JV_ACCOUNT_CODE
, JV_NOTES: _JV_NOTES
, JV_DATE: _JV_DATE
, JV_DEBIT_AMOUNT: _JV_DEBIT_AMOUNT
, JV_CREDIT_AMOUNT: _JV_CREDIT_AMOUNT
});
}
For more you can also see this:

Related

Reload data to textbox after jqgrid "reloadGrid" action

I use a modal form to update/create my records "reloadGrid" method enables the grid enter image description here to refresh from within the modal "save" bouton, but
1) my form below does not get updated.
2) the last selected row on the jqGrid table gets not selected.
I tried to manualy force the row to be selected with
jQuery('#grid').jqGrid('setSelection', selRowID, true);
but selected row returns null.
Below is the function that saves the updated record and is suposed to trigger the grid and the controls update:
//function SauvegarderMessage(IDMessage) {
function ModifierDemandeur() {
//console.log("Modifier");
var xCodeDdeur = $('#txtCode_Demandeur').val();
var xAddDdeur = $('#txtAdresse_Demandeur').val();
var xIDVille = $('#cbxVille_Demandeur').val();
var xIDProv = $('#cbxProvince_Demandeur').val();
var xCPDdeur = $('#txtCodePostal_Demandeur').val();
var xTel1Ddeur = $('#txtTel1_Demandeur').val();
var xTel2Ddeur = $('#txtTel2_Demandeur').val();
var xTel3Ddeur = $('#txtTel3_Demandeur').val();
var xCour1Ddeur = $('#Courriel1_Demandeur').val();
var xCour2Ddeur = $('#Courriel2_Demandeur').val();
var xCour3Ddeur = $('#Courriel3_Demandeur').val();
var xIDSitMat = $('#cbxSitMat_Demandeur').val();
var xIDSexe = $('#cbxSexe_Demandeur').val();
var xDteNais = $('#txtDteNaissance').val();
var xRevDdeur = $('#txtrevenu_demandeur').val();
var xIDOcc = $('#cbxOccupation_Demandeur').val();
var xIDScol = $('#cbxScolarite_Demandeur').val();
var xIDStatLegal = $('#cbxStatutLegal_Demandeur').val();
var xIDComm = $('#cbxCommunaute_Demandeur').val();
var xIDSceInfo = $('#cbxSourceInformation_Demandeur').val();
var xHandicape = $('#cbHandi').val();
var xRef = $('#txtReference_Demandeur').val();
var xRemDdeur = $('#Remarques_Demandeur').val();
$.ajax({
type: "POST",
url: "../Conseiller/UpdateDemandeurs",
data: {
Code_Demandeur: xCodeDdeur,
Adresse_Demandeur: xAddDdeur,
ID_Ville: xIDVille,
ID_Province: xIDProv,
CodePostal_Demandeur: xCPDdeur,
Tel1_Demandeur: xTel1Ddeur,
Tel2_Demandeur: xTel2Ddeur,
Tel3_Demandeur: xTel3Ddeur,
Courriel1_Demandeur: xCour1Ddeur,
Courriel2_Demandeur: xCour2Ddeur,
Courriel3_Demandeur: xCour3Ddeur,
ID_SituationMatrimoniale: xIDSitMat,
ID_Sexe: xIDSexe,
Date_Naissance_Demandeur: xDteNais,
Revenu_Demandeur: xRevDdeur,
ID_Occupation: xIDOcc,
ID_Scolarite: xIDScol,
ID_StatutLegal: xIDStatLegal,
ID_Communaute: xIDComm,
ID_SourceInformation: xIDSceInfo,
Handicape: xHandicape,
Reference: xRef,
Remarques_Demandeur: xRemDdeur,
},
dataType: "json",
success: function (data) {
//console.log(data)
//console.log(data.rows);
$('#modifierProfilModal').modal('hide');
if (data != null) {
jQuery('#grid').jqGrid('clearGridData')
.jqGrid('setGridParam', { data: data, datatype: 'json' })
.trigger('reloadGrid')
for (var i = 0; i < data.Data.records; i += 1) {
var selRowID = data.Data.rows[i].Code_Demandeur;
var selectedRowID = $('#btnModifierProfile').val();
if (selRowID == selectedRowID) {
//jQuery('#grid').jqGrid('setSelection', selRowID, true);
var selr = jQuery('#grid').jqGrid('getGridParam', 'selrow');
console.log('Ligne sélectionnée: ' + selr);
return;
}
}
}
},
error: function (err) { console.log(err); }
});
I tried editRow action to force row selection, I tried to set focus to the grid, nothing would do.
A work around would be to identify each field with the last selected element's ID and assign each control appropriate value using document.getElementById('controlID').value = some_json_returned_data;
But this still not solve the grid row selection issue and does not seem to be a "best practice" way to do.
Coding the "loadComplete" method of qgrid resolved both issue:
loadComplete: function () {
if ($('#btnModifierProfile').val() != "")
jQuery('#grid').jqGrid('setSelection', $('#btnModifierProfile').val());
},
Desired row is selected and related data populated in other controls.

Meteor mongodb insert document of an array

This code has the server insert some documents in a collection for the client to find it later.
I need to return the array for a given task
But the page is saying
No data received
Why is that and how to fix it? Thanks
//Both
FooterButtons2 = new Mongo.Collection('footerButtons2');
//Server
Meteor.publish('footerButtons2', function(){
return FooterButtons2.find();
});
FooterButtons2.insert(
{ "task1": ["submit"]},
{ "task2": ["cancel","continue"]}
);
//client
Meteor.subscribe('footerButtons2');
var res = FooterButtons2.findOne("task1");
When you search like this:
var res = FooterButtons2.findOne("task1");
you are searching an object that has the "_id" key equal to "task1", this is not correct.
You want the object that has the key "task1" in it. The correct way would be:
var res = FooterButtons2.findOne({
task1: { $exists: true }
});
But ideally, you should be doing searches based on values and not keys. Something like this:
FooterButtons2.insert({
task: "task1",
buttons: ["submit"]
}, {
task: "task2",
buttons: ["cancel", "continue"]
});
var res = FooterButtons2.findOne({
task: "task1"
});

Reactive cursor without updating UI for added record

I am trying to make a newsfeed similar to twitter, where new records are not added to the UI (a button appears with new records count), but updates, change reactively the UI.
I have a collection called NewsItems and I a use a basic reactive cursor (NewsItems.find({})) for my feed. UI is a Blaze template with a each loop.
Subscription is done on a route level (iron router).
Any idea how to implement this kind of behavior using meteor reactivity ?
Thanks,
The trick is to have one more attribute on the NewsItem Collection Say show which is a boolean. NewsItem should have default value of show as false
The Each Loop Should display only Feeds with show == true and button should show the count of all the items with show == false
On Button click update all the elements in the Collection with show == false to show = true
this will make sure that all your feeds are shown .
As and when a new feed comes the Button count will also increase reactively .
Hope this Helps
The idea is to update the local collection (yourCollectionArticles._collection): all articles are {show: false} by default except the first data list (in order not to have a white page).
You detect first collection load using :
Meteor.subscribe("articles", {
onReady: function () {
articlesReady = true;
}
});
Then you observe new added data using
newsItems = NewsItems.find({})
newsItems.observeChanges({
addedBefore: (id, article, before)=> {
if (articlesReady) {
article.show = false;
NewsItems._collection.update({_id: id}, article);
}
else {
article.show = true;
NewsItems._collection.update({_id: id}, article);
}
}
});
Here is a working example: https://gist.github.com/mounibec/9bc90953eb9f3e04a2b3.
Finally I managed it using a session variable for the current date /time:
Template.newsFeed.onCreated(function () {
var tpl = this;
tpl.loaded = new ReactiveVar(0);
tpl.limit = new ReactiveVar(30);
Session.set('newsfeedTime', new Date());
tpl.autorun(function () {
var limit = tpl.limit.get();
var time = Session.get('newsfeedTime');
var subscription = tpl.subscribe('lazyload-newsfeed', time, limit);
var subscriptionCount = tpl.subscribe('news-count', time);
if (subscription.ready()) {
tpl.loaded.set(limit);
}
});
tpl.news = function() {
return NewsItems.find({creationTime: {$lt: Session.get('newsfeedTime')}},
{sort: {relevancy: -1 }},
{limit: tpl.loaded.get()});
},
tpl.countRecent = function() {
return Counts.get('recentCount');
},
tpl.displayCount = function() {
return Counts.get('displayCount');
}
});
Template.newsFeed.events({
'click .load-new': function (evt, tpl) {
evt.preventDefault();
var time = new Date();
var limit = tpl.limit.get();
var countNewsToAdd = tpl.countRecent();
limit += countNewsToAdd;
tpl.limit.set(limit);
Session.set('newsfeedTime', new Date());
}
});

How to add CSS StyleClass when instantiating object, instead of object.addStyleClass("myStyle")

I work with SAPUI5, and I want to add a style to an object as soon as I instantiate it. For example, I want to add styleclass 'foo' to my label inside my panel.
What I want to do, but doesn't work:
var oPanel = new sap.m.Panel({
content: new sap.m.Label({
text: "Hello",
styleClass: "foo"
})
});
What I don't want to do, but does work:
var oLabel = new sap.m.Label({
text: "Hello"
});
oLabel.addStyleClass("foo");
var oPanel = new sap.m.Panel({
content: oLabel
});
There's another option based on method chaining which does not require a dedicated variable for the inner elements (which I guess is the reason why you do not like the 2nd variant in your question):
var oPanel = new sap.m.Panel({
content: new sap.m.Label({ text: "Hello" }).addStyleClass("foo")
});
you can even write your own custom classes where the style class is an aggregation. I am not sure as yet how this can be done but I was able to write custom labels with 'color' aggregation.
You could create a function to return your control instances, and inside of it make use of the addStyleClass method, and others you would like
function getControlInstance(FnClass, sId, mSettings) {
mSettings = mSettings || {};
if (typeof sId !== "string") {
mSettings = sId;
sId = null;
}
var oControl = new FnClass(sId, mSettings);
if (mSettings.styleClass) {
mSettings.styleClass = mSettings.styleClass instanceof Array ? mSettings.styleClass : [mSettings.styleClass];
mSettings.styleClass.forEach(function (sClass) {
oControl.addStyleClass(sClass);
});
}
return oControl;
}
Use like this
var a = getControlInstance(sap.m.HBox, {
styleClass: "test",
id: "asdoiasd",
items: [
new getControlInstance(sap.m.Text, {
styleClass: "test",
text: "Testing"
})
]
})

How to read value when using model.save() or fetch()?

Man = Backbone.Model.extend({
url:'/test.aspx',
initialize: function(){
},
defaults: {
name:'Jim',
age: '38'
},
validate:function(attributes){
if(attributes.name == '') {
return "name can't be null";
}
}
});
var man = new Man;
man.set({name:'the5fire'});
man.save(); //the format is json{"name":"the5fire","age":38}
In test.aspx.cs, how can I read this value {"name":"the5fire","age":38} ?
I have tried Request.Form.ToString() but found no data there.
Chrome developer tools shows this json-format data in the "request payload" block.
update:
If I use man.fetch({ data: { Pagesize: '1', PageIndex: '111' } ), then on the server side, I can use Request.Params["PageIndex"]. But how can I get the name? the age?
You can access the raw body of the request via HttpRequest.InputStream and convert it to a string :
string jsonstring = new System.IO.StreamReader(Request.InputStream).ReadToEnd();
You would then deserialize this string to get an object, for example:
using System.Web.Script.Serialization;
JavaScriptSerializer jss = new JavaScriptSerializer();
var d = jss.Deserialize<dynamic>(jsonstring);
string name = (string)d["name"];

Resources