How do I get the values in php variables from a selected row in phpgrid? - phpgrid

I am trying to populate fields in a html form getting data values from a row selected by a user in phpgrid. So the phpgrid has a table from the database and I want to select a row which then gets populated in a html form. I tried using AJAX variables but nothing work. Please help me out.

You can do by creating a ShowSelectedRows function.
<script type="text/javascript">
function ShowSelectedRows(){
var rows = getSelRows();
var dataIDs = $('#Data2').getDataIDs(); // #Data2 is the name given to your table
gdata = $('#Data2').jqGrid('getRowData', rows[0]);
console.log(gdata);
}
</script>
Ensure to enable multiselect for rows. Hope it helps!

Related

In Google AppMaker, How to filter using a single DateBox?

I am trying to filter a table using a DateBox. The problem I have is that it doesn't display the records of that day when binding value is set to #datasource.query.filters.date._equals. However, it does work when the filter is _greaterThanOrEquals, but it also includes later records.
I am using SQL tables with date field type is DATE.
It's a bug. We're looking into it.
For now please use workaround:
Remove the binding and set 2 filters in onValueEdit event with code like:
widget.datasource.query.filters.FIELD_NAME._greaterThanOrEquals = newValue;
widget.datasource.query.filters.FIELD_NAME._lessThanOrEquals = newValue ? new Date(newValue.getTime() + 24*60*60*1000) : null;
widget.datasource.load();
bind DateBox value to
#datasource.query.filters.NameOfDateFiled._equals
and don't forget reload datasource in "onValueChange" event.

How Can I Duplicate A Item/Record?

(Deleted my old question to simplify it. )
I enter data in a table, I then want to make an exact duplicate of that data in a new item/record/row*.
*not sure the proper term.
Is there any way to accomplish this?
Sorry for the slow response. Here is what you should do:
Add a "copy" button in the row. In the onClick on that button, add this code:
var createDataSource = widget.datasource.modes.create;
var rowDataSource = widget.datasource;
createDataSource.item.foo = rowDataSource.item.foo;
createDataSource.item.bar = rowDataSource.item.bar;
// And so on for each field
createDataSource.createItem();
You could probably make sure of javascript for-in to loop through all the properties of the item in so you don't have to manually specify each record, but I didn't have time to experiment with this.
Edit:
The above code won't show the copied record in the list immediately, because I used row's create data source, instead of the lists create data source. Try this instead:
var rowDataSource = widget.datasource;
// Instead of using the row datasource for create, explicitly use the data source of your list.
var listDatasource = app.datasources.NameOfYourListsDataSource;
var createDataSource = listDatasource.modes.create;
createDataSource.item.foo = rowDataSource.item.foo;
createDataSource.item.bar = rowDataSource.item.bar;
// And so on for each field
createDataSource.createItem();

How to Get row by key value or visible index in ASPxGridView then change column value?

Hi
In ASPxGridView, is there a way to get a row by its VisibleIndex or KeyValue so that I can change any column value in it?, I mean something like this:
var row = myGrid.SelectRowByKeyValue(myKeyValue);
OR:
var row = myGrid.SelectRowByVisibleIndex(myKeyValue);
row["Column1"] = true;
Edit:
What I'm tring to do is that every time I hit the button I want to check one specific row (I'm using ajax to not reload all the page);
Thanks
This can be done using the ASPxGridView.GetRow() method. NOTE, that changing the value in the DataRow is not enough. If you want these changes to be preserved, save them to the DB.
Since you are using unbound columns, you should handle the CustomUnboundColumnData event and provide modified data for this row within this event handler. The common approach is described in the Providing Data for Unbound Columns topic. If this does not help, please describe in greater details.
UPDATE
Your approach is incorrect. The ASPxGridView does not provide a method to set a text of a certain cell (TD). Instead, you should force the grid to raise the CustomUnboundColumnData event. This can be done using the ASPxGridView's DataBind method. In this event handler, you should determine the KeyField value of the processed row, compare it with the keyField value of the row where the button was clicked and return the required value. This is how I would implement this feature...
I solved it by using this code:
for (int i = 0; i < myGridView.VisibleRowCount; i++)
{
if ( [My condition] )
{
(
(CheckBox)myGridView
.FindRowCellTemplateControl(i,
myGridView.Columns["MyColumnName"] as GridViewDataColumn,
"My_Unbound_Control_Name"
)
).Checked = true;
}
}
I's may not be the right way to do it but I couldn't solve it another way.

ASP.Net Auto-populate field based on other fields

I've just moved to web development and need to know how i can implement below requirement using asp.net and vb.net.
I have three fields in a form which are filled by users. Based on these three values, i need to auto-populate the 4th field. I have planned to implement this in the following way
Write a separate class file with a function to calculate the possible values for the 4th fields based on 1st 3 inputs. This function can return some where between 1-10 values. So I've decided to use drop-down for 4th field, and allow users to select the appropriate value.
Call the above function in onchange function of 3rd field and take and use the return values to populate the 4th field. I'm planning to get the return values in array field.(Does this need a post back?)
Please let me know how if there is better way to implement this.
Thanks.
You may want to consider doing this with Javascript. You could read and control the fields pretty easily with pure Javascript, or using a nice library like jQuery (my favorite). If you did it this way, no post-back would be required and the 4th field would update immediately. (Nice for your users)
You can also do it with ASP.NET for the most part. "onchange" in ASP.NET still requires Javascript as far as I know, it just does some of it for you. A post-back will definitely happen when you change something.
You need javascript or to set autopostback=true on your form elements.
From a user perspective the best thing is to use javascript to populate the field for display, BUT when the form is submitted use your backend function to validate it. This will make sure the user didn't change the value.
An easy way is to use jQuery for the UI (that way you don't have to worry about long winded javascript and deal with browser compatibility as it's already taken care of for you) and have it call to the server for the data. For the server, your easiest route is to return JSON for looping values.
Include your jQuery:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
Then add in a handle for the JavaScript:
<script type="text/javascript">
function autoPopulate() {
var value1 = $('#ddl1').val();
var value2 = $('#ddl2').val();
var value3 = $('#ddl3').val();
var url = 'path/to/your/file.aspx?value1=' + value1 + '&value2=' + value2 + '&value3=' + value3;
$.getJSON(url, function(data) {
data == null ? return false : data = eval(data);
var ddl = $('#ddl4')[0];
for (i = 0; i < data.length; i++) {
var option = new Option(data[i][0], data[i][1]);
if ($.browser.msie) {
ddl.add(option);
} else {
ddl.add(option, null);
}
}
}
}
</script>
(Yes, I know I used a native loop but I'm little lazy here today :) )
Now, for your server side code you'll want your code your page to return data in the format of:
[['value1','text1'],['value2','text2'],['value3','value3']]
so something like:
<script type="vb" runat="server">
Private Sub Page_Init()
// get your data
// loop through it and add in values
// ex.
Dim result As String = "[" //start multi-dimensional array
For Each Item As String In data
result += String.Format("['{0}','{1}'],", _value, _text)
Next
result = result.SubString(0, result.Length - 1) // removes trailing comma
result += "]" // closes off m-array
Response.Write(result)
Response.Flush()
End Sub
</script>

How to update a table row with save button using .ajax

I have a table which has one row and only one cell will be editable. I have accomplished this with the following code.
$("td#effEndDate").click(function() {
if (!$(this).hasClass("edit")) {
var value = jQuery.trim($(this).html());
$(this).html("<input id=\"txtEdit\" type=\"text\" value=\"" + value + "\" />");
$(this).addClass("edit");
$("#txtEdit").focus();
}
});
Now this is the part where i'm stuck.
After the field is updated a save button must be clicked to call the proper .ajax method to update the database. But how can I compare the previous value to the current value on a button press? Since i'm not using the onblur property where I could have saved the old value and passed it to the update function.
There are two possibilities.
Pass the variable around in between functions
Make the variable global
if you want the variable global do not use the "var" keyword
Change:
var value = jQuery.trim($(this).html());
To this:
value = jQuery.trim($(this).html());
Edit
If the click function is getting hit more then once before a page refresh and assuming you want to keep a copy of the original table rows you can try this. Save a copy of the original table in a variable then you can query the original table for the html using the ID number. Here is a quick mock
first store the table in a variable upon the page loading. This will save an original copy of the table
//get a copy of the table
var GetCopyofOriginalTable = function() {
var TableToBeCopied = $('the appropriate selector');
CopyOfTable = JQuery.extend(true, {}, TableToBeCopied); //Notice no var, its global
}
//Now store the variale
GetCopyofOriginalTable();
var FindTableRowByID = function(trID) {
return $('table:has(tr#' + trID));
}
Now you can loop through the new table test its value agaisnt the old table. This methed make use alot of memory depending on how big the table is.
I would store the original value somewhere in a variable, and compare the two in the submission function before sending the .ajax call.

Resources