Inline Edit data on MVCContrib grid and save bulk chanegs - asp.net-mvc-4

I am using "MvcContrib.Mvc4" to show my grid on a page in my project.
I need to have a grid with some columns which are from filtered data (From Source table), and have 3 in-line editable column, like StartDate, EndDate, Notes and need to insert them into new table(The Destination Table)
I can use the Html.EditorFor(c=>c.StartDate) in my columns, and edit them on the grid, but I don't know how to track the changes and save their updates into data base!
Also I have the column of "Notes" which is not in the model, but I need to insert it into new table with the other changed data (To the destination table)
After I edited data, in the source of page, the value is not changed.
I need to give the user the ability of editing (these three columns) on many rows and after submitting the "Save" button, Save bulk changes from grid into another new table!
I am thinking of a way to get changes and send them all to server by client side code like Jquery or Ajax, But I could not find any good example of this on internet.
I know how to check boxes on the grid and get the selected ids form the page, but I don't know how to get changed Text fields and Dates from grid.
I appreciate any help or sample code!
Here are some codes
#Html.Grid(Model.Enrolments).WithModel(new EnrolmentGrid()).Columns(column =>
{
column.For(i => Html.EditorFor(x => i.EndDate)).Named("End Date");
column.For(i => Html.EditorFor(x => i.StartDate)).Named("Start Date");
column.For(i => Html.Editor("Notes", new { /*Not sure if this is correct*/ value = i.EnrolmentId, #class = "Notes" })).Named("Notes");
}).Attributes(#class => "full-grid-style")}

Related

Transaction BODY Field from COLUMN Field (Netsuite)

I have an issue where some of our orders are being imported directly into Netsuite, and there is information from the first line item, that I need to copy into the transaction record (i.e. custom field on sales order)
I want to set this up so that it is automatic, I don't have access to the system that is used to bring the orders into Netsuite, and I only JUST got suitescript access and everything I read about that is way above my head..
I know basic HTML and some of the scripting formulas from Netsuite and that's all.
I was hoping there would be a CUSTOM FIELD FORMULA or some other similar way that I can just easily source the information directly from the first item in the item sublist?
This would be quite trivial to implement using SuiteScript. The example below assumes you want to copy the Memo field (description) from the first line item to the body Memo field. The basic idea would be something like the below (untested code):
function userEventBeforeSubmit(type){
if (type === 'create') {
var record = nlapiGetNewRecord();
var memo = record.getLineItemValue('item', 'memo', 1);
record.setFieldValue('memo', memo);
}
}
If want to accomplish this via custom fields etc. it is possible using "Custom Fields with Values Derived from Summary Search Results".
To do this create a Saved Search as follows:
Type: Transaction
Criteria: [none]
Results: Formula (Text), Summary
Type = Maximum, Formula: DECODE({line}, 1, {memo}, NULL)
Available Filters: Internal ID
Then create a Custom Transaction Body Field as follows:
Type: Free Form Text
Store Value: F
Validation & Filtering > Search: [Saved Search from previous step]
As this is a dynamically calculated field (Store Value = F), it would be available when viewing the record, but not in Saved Searches and lists. To remove this limitation, you can create a Workflow that would copy this field to another one that is stored.

yii cGridView multicomment

I'm not sure what is the way to do this , so here I ask:
I have a Person model and Event model, and a connection table Person_Event.
The interface that I got now works in the following way:
A person is logging in and his id is being send via URL
The person is selecting events he is interested in from the cGridView (checkbox column)
Writing some comment
4.Pressing send button , and the following create action is being triggered:
public function actionXcreate()
{
$model=new Person_Event;
if(isset($_POST['Person_Event']))
{
foreach ($_POST['selectedIds'] as $eventId)
{
$pmodel=new Person_Event;
$pmodel->person_id=$this->_person->id; //the id of the person who is logged in
$pmodel->attributes=$_POST['Person_Event']; //the comment
$pmodel->event_id = $eventId; //all the events he checked in the grid
if (!$pmodel->save()) print_r($pmodel->errors);
}
$this->redirect(array('site/success'));
}
So far , all is logical and simple. However , what I end up is that the comment the person wrote is being duplicated to every person_event row in the DB.
I want to put a text box in each row of the grid , and the commnet that will be written there will go to the specific event.
Now , I found this topic in yii about "admin-panel"
which is kind of helpful , BUT:
I already have a foreach in the action , the one that matches the person's id with the event's id , so how can I put another individual comment for each combo?
The default CGridView supports only basic functionality, you would need to extend CGridView or use an extension to make columns editable
Easiest way to do this is use something like TbEditableColumn from Yii-booster library
see http://yiibooster.clevertech.biz/extendedGridView#gridcolumns EditableColumn in the additional column types section
If you do not like or wish to use twitter-bootstrap styling a standalone extension like http://www.yiiframework.com/extension/eeditable will help.
Alternatively you can extend CGridView yourself to extend it to support column level editing

Titanium android data reflection in table view

Google APIs Android 2.3.1 , data changes in the database tables not reflecting in tableview screens, but if we restart the app, will show changes and also, if we load app.js will show recent changes.
Can anyone help me to fix this??
fireEvent("db_update")
&
addEventListener('db_update', function() { what should be here to update table data })
For updating a database, you need to remove it first, and then install a new one. Or run queries to update the current one.
This is how I update my database, based on a version number I store in the properties:
function updateDatabase(version){
if (version != Ti.App.Properties.getInt('version',0)){
sb.db.remove();
sb.db = Ti.Database.install('/lib/db.sqlite','db');
Ti.App.Properties.setInt('version',version);
}
}
In the app, on start, I run the function with a manual typed version number in it. Every time your database changes you can manually change this number.
updateDatabase(5);
This of course does not reflect a regular update on the content of a table. (when you run a regular query on the database).
In that case, you should rebuild the content of the tableview yourself (you have the code to fill the tableview, rerun that code) or find a way to target the exact row you need to change with an ID for example.
I found the solution,
Ti.App.addEventListener('updatedb', updateData);
here 'updateData' is the function which gets the data for tableview from the databae. At the
bottom of 'updateData' function, set data for table view
i.e) tableview.setData(data);
and then, your insert, update or delete function should trigger 'updatedb' function
i.e)
function deleteData(recId) {
var db = Ti.Database.open(DBNAME);
db.execute(" DELETE FROM tblName WHERE id IN("+ recId+") ");
db.close();
Ti.App.fireEvent('dataupdated');
}
now, after calling deleteData function, your tableview data will show w/o deleted record.

query single dropdown menu with multiple dropdown menus via rails

I'm having some difficulty figuring out the following problem. I apologize if this writeup is slightly confusing, but I'll try to explain it as best as I can.
I'm relatively new to rails, and I'm trying to implement a query on my site. One portion of my site allows users to select a State from a dropdown menu when filling out a form.
Another portion of the site, (the portion that implements the query) allows users to query for a form based on the State associated with it. The page is essentially only 4 dropdown boxes, and a submit button. This query should allow users to find forms from multiple States by selecting the desired States from the available dropdown menus. Meaning a user can query for forms from 4 different states, and it would return all forms where the state on the form matches the state from one of the four dropdown menus.
So, a user can select "Georgia" from state_1 (name of dropdown), "Texas" from state_2, "California" from state_3, and "Ohio" from state_4. Once a user submits their search, I would like to return all the forms available that match the user's dropdown selections.
I'm running into some issues at present. here is the code I currently have:
def self.search(params)
form = self.scoped
form = form.where(:state => params[:state_1]) if params[:state_1].present?
form = form.where(:state => params[:state_2]) if params[:state_2].present?
form = form.where(:state => params[:state_3]) if params[:state_3].present?
form = form.where(:state => params[:state_4]) if params[:state_4].present?
form
end
The issue i am running into is the following: If I run a query with only a selection on state_1, then it returns all of the fields associated with that state (which is excellent); however, if I try to run a query with selections on multiple dropdown menus (for example, "Georgia" on state_1 and "Texas" on state_2) no forms are returned.
Again, I sincerely apologize if this is confusing, and I'm grateful for your time. I would appreciate any help and I'll do my best to respond to any questions as prompt as possible. Thank you so much!
If you have both :state_1 and :state_2 set, then you'll be doing this:
form = form.where(:state => params[:state_1]).where(state => params[:state_2])
And that's saying
state = 'TX' AND state = 'GA'
Each time you call .where, you're appending another condition with a conjunction (i.e. AND). I think you're after this:
states = [:state_1, :state_2, :state_3, :state_4].map { |k| params[k] }.reject(&:blank?)
form = form.where(:state => states) if(!states.empty?)
That will turn into SQL sort of like this:
state IN ('TX', 'GA')
and that seems to be what you're after. The map will extract the param values with for the specified state keys and then the reject will filter out the blank ones (i.e. false, nil, empty, or all whitespace).

how to represent trees and their content in MySQL?

I need to be able to store something like this:
where the green is a template type, the gray is a field container type, and the white is field. (That being, a field has a label and some text, both mediumtext for simplicity; and a field container can store other field containers or text, and a template is a top-level field.)
Now, let's say I want to allow users to create any number of these structures, but it is unlikely to be more than say 10. And, of course, we need to be able to link data to it.
This is all to be able to store in a database an associative array that looks for the above like, in pseudo code:
my_template = {
page_info => { description => 'hello!!!' },
id => 0,
content => { background_url => '12121.jpg', text => ...
}
Having an easy way to add a field to all data using the template when the template changes (say, we add a keywords to page_info) would be a big plus.
I can't figure this out at all, thanks a lot!
There are several different ways to store heirarchical data structures (trees) in MySQL. You can for example choose:
Adjacency list
Nested sets
Path enumeration
Closure table
See Bill Karwin's presentation for more details on the pros and cons of each.