jquery flexigrid edit array without read database table - flexigrid

i add content in flexigrid directly
( see at Flexigrid loading data from local json object or Populate Flexigrid with an array or populate it by code )
and how can i edit the array that i was pushed in without via << $("#flex1").flexigrid({ url: >> function ?

found the solution by DOM
https://groups.google.com/forum/?fromgroups=#!topic/flexigrid/0oRmeJRAnpc
function getSelectedRow() {
var arrReturn = [];
$('.trSelected').each(function() {
var arrRow = [];
$(this).find('div').each(function() {
arrRow.push( $(this).html() );
});
arrReturn.push(arrRow);
});
return arrReturn;
read as array

Related

How can I to empty the content of html tag?

Hello I am loading a few of data each API call, inside a tag, but when I do the second call this data is appended to the data of the previous call.
The question is how can I clear the content of a div?
I am using this for select that div
this.$refs.data
In order to add contet I am using the following code:
responseJSON.forEach(element => {
let card = Vue.extend(card)
let instance = new card({
propsData: {
ch: element
}
})
instance.$mount()
this.$refs.aaa.appendChild(instance.$el)
this.cards.push(instance)
});
Before running the responseJSON.forEach, you can clear everything in the div first by running
this.$refs.data.innerHTML = ""

3 way binding using firebaseObject opened in input fields

Hi I'm trying to make 3 way binding work on objects opened in input fields (Doesn't have to be Object)
The idea is to open an object in a div with the results of the object inside input fields, and to change the values of that object one would just need to change the data in those fields and the changes would be made to the objects values directly.
Anyone done something like this?
EDIT
I have done the simpler guides on firebase.com but for my project there is several fields on the object, I deleted the code I tried with but it was something similar to this.
Controller
$scope.loadModel = function($id) {
var rec = $firebaseObject(new Firebase('https://****.firebaseio.com/models/' + $id));
rec.$loaded().then(function(rec){
var record = rec;
$scope.record = record;
console.log(record.name);
var child = rec.client.id;
record.$bindTo($scope, "record").then(function() {
console.log($scope.data);
$scope.data.foo = "baz";
record.set({ foo: "baz" });
});
var obj = $firebaseObject(new Firebase('https://dam-db.firebaseio.com/clients/'+child));
obj.$loaded().then(function(obj){
$scope.object = obj;
console.log(obj.name);
//return obj;
})
})
};
Html
<div ng-model="record" ng-repeat="record in record">
<input value="{{record}}"></input>
</div>

How can I remove all items from a Dojo dstore?

I am having trouble removing all items from a dstore. I am trying this, which seems like it should work, but it fails at the end:
var TrackableMemory = declare([ Memory, Trackable ]);
var userMem = new TrackableMemory({
data: {the data...},
idProperty: '_id'
});
userMem.forEach(function (userObj) {
userMem.remove(userObj._id);
});
I put up a working (or not working, rather) example in this fiddle. See the console for the "cannot read property '_id' of undefined" error when it can't find the last record.
I have other things connecting to this store instance, so I can't really just reset everything by redefining userMem.
What am I doing wrong? How can I remove all items from a dstore?
Turned out to be a simple JS array problem of modifying the array over which I was iterating. Looping backwards over the array with a simple for works:
userMem.fetch().then(function (users){
for (var i = users.length - 1; i >= 0; i--) {
userMem.remove(users[i]._id);
}
});
This worked for me
// Forget all data
myGrid.store.data = [];
// Refresh the grid
myGrid.refresh();

Pass data-attribute value of clicked element to ajax settings

For an implementation of Magnific Popup, I need to pass a post id to the ajax settings. The post id is stored in a data attribute of the element to which Magnific Popup is bound. I would like this to work:
html element:
<a data-id="412">Clicke me</a>
Javascript:
$('.element a').magnificPopup({
type: 'ajax',
ajax: {
settings: {
url: php_array.admin_ajax,
type: 'POST',
data: ({
action:'theme_post_example',
id: postId
})
}
}
});
Where postId is read from the data attribute.
Thanks in advance.
$('.element a').magnificPopup({
callbacks: {
elementParse: function(item){
postData = {
action :'theme_post_example',
id : $(item.el[0]).attr('data-id')
}
var mp = $.magnificPopup.instance;
mp.st.ajax.settings.data = postData;
}
},
type: 'ajax',
ajax: {
settings: {
url: php_array.admin_ajax,
type: 'POST'
}
}
});
Here is how to do it:
html:
<a class="modal" data-id="412" data-action="theme_post_example">Click me</a>
jquery:
$('a.modal').magnificPopup({
type: 'ajax',
ajax: {
settings: {
url : php_array.admin_ajax,
dataType : 'json'
}
},
callbacks: {
elementParse: function() {
this.st.ajax.settings.data = {
action : this.st.el.attr('data-action'),
id : this.st.el.attr('data-id')
}
}
},
parseAjax: function( response )
{
response.data = response.data.html;
}
});
php
function theme_post_example()
{
$id = isset( $_GET['id'] ) ? $_GET['id'] : false;
$html = '<div class="white-popup mfp-with-anim">';
/**
* generate your $html code here ...
*/
$html .= '</div>';
echo json_encode( array( "html" => $html ) );
die();
}
As this answer was the original question regarding inserting data into Magnific's ajax call, I'll post this here.
After many hours of trying to figure this out, you should know that if you're using a gallery with the ability to move between gallery items without closing the popup, using elementParse to set your AJAX data will fail when you visit an item after already viewing it (while the popup is still open).
This is because elementParse is wrapped up in a check that it makes detect if an item has already been 'parsed'. Here's a small explanation as to what happens:
Open gallery at item index 2.
Item has not been parsed yet, so it sets the parsed flag to true and runs the elementParse callback (in that order). Your callback sets the ajax options to fetch this item's data, all is well.
Move (right) to item index 3.
Same as above. The item has not been parsed, so it runs the callback. Your callback sets the data. It works.
Move (left) back to item index 2.
This time the item has been parsed. It skips re-parsing the item's element for assumed potential performance reasons.Your callback is not executed. Magnific's ajax data settings will remain the same as if it were item index 3.
The AJAX call is executed with the old settings, it returns with item index 3's data instead, which is rendered to the user. Magnific will believe it is on index 2, but it is rendering index 3's data.
To resolve this, you need to hook onto a callback which is always executed pre-ajax call, like beforeChange.
The main difference is that the current item isn't passed through into the callback. Fortunately, at this point, magnific has updated their pointers to the correct index. You need to fetch the current item's element by using:
var data = {}; // Your key-value data object for jQuery's $.ajax call.
// For non-closures, you can reference mfp's instance using
// $.magnificPopup.instance instead of 'this'.
// e.g.
// var mfp = $.magnificPopup.instance;
// var itemElement = mfp.items[mfp.index].el;
var itemElement = this.items[this.index].el;
// Set the ajax data settings directly.
if(typeof this.st.ajax.settings !== 'object') {
this.st.ajax.settings = {};
}
this.st.ajax.settings.data = data;
This answer can also be used as a suitable alternative to the currently highest voted, as it will work either way.
You may use open public method to open popup dynamically http://dimsemenov.com/plugins/magnific-popup/documentation.html#public_methods
postId = $(this).attr('data-id')
$(this) retrieve the current element (the link you clicked on), and attr the value of the specified attribute.

Simple store connected list for dojo

Is there a simpler list type than DataGrid that can be connected to a store for Dojo?
I would like the data abstraction of the store, but I don't need the header and cell stucture. I would like to be more flexible in the representation of the datalines, where maybe each line calls an function to get laid out...
You ask a really good question. I actually have a blog post that is still in draft form called "The DataGrid should not be your first option".
I have done a couple thing using the store to display data from a store in a repeated form.
I have manually built an html table using dom-construct and for each.
var table = dojo.create('table', {}, parentNode);
var tbody = dojo.create('tbody', {}, table); // a version of IE needs this or it won't render the table
store.fetch({ // this is a dojo.data.ItemFileReadStore, but you cana dapt to the dojo.Store API
query: {},
onComplete: function(itms) {
dojo.forEach(itms, function(itm, idx) {
var tr = dojo.create('tr', {}, tbody);
// use idx to set odd/even css class
// create tds and the data that goes in them
});
}
});
I have also created a repeater, where I have an html template in a string form and use that to instantiate html for each row.
var htmlTemplate = '<div>${name}</div>'; // assumes name is in the data item
store.fetch({ // this is a dojo.data.ItemFileReadStore, but you cana dapt to the dojo.Store API
query: {},
onComplete: function(itms) {
dojo.forEach(itms, function(itm, idx) {
var expandedHtml = dojo.replace(htmlTemplate, itm);
// use dojo.place to put the html where you want it
});
}
});
You could also have a widget that you instantiate for each item.