The two "design defects" Saved by the datagrid are edited directly.

Source: Internet
Author: User

The two "design defects" Saved by the datagrid are edited directly.

The "design defect" Saved by the direct editing of the datagrid only solves how to enable the background to receive data from the foreground.

However, I am still confused about how to save the front-end data temporarily ~

So this article is followed by the subsequent processing of the previous Article ~ The focus is not on discussing "design defects ~


Because it seems that js does not have a set type, the array in js is used to save the data.

Here are a few questions:

1. Each time the edit is completed (endEdit), the edit row is saved. There are three cases (save, add, and click another row)

It is worth noting that clicking the input or other elements outside the datagrid will not cause the row being edited by the datagrid to lose the focus ~

2. When deleting an array, you must be able to delete the elements in the array (what is used for association ?)

The original idea was: if the existing record was identified by a primary key id, the row can be deleted when the row is deleted, but what if it was created? What should I do if no id has been assigned?

Then the idea was denied.

The second idea: manually assign a unique identifier to them on the page. This idea should be feasible, but it is a little troublesome.

Is there a simpler way? Suddenly, the data in the list corresponds to the data in the array!

The data in the list is a visual display of the data structure in array! The order is exactly the same, so we can associate the two with subscripts!


According to the demo on the official website, the endEdit method is provided, which is called when editing is completed and verified. below is my rewrite.

Specifically, translation is not implemented on the official website, but with the velocity Directive: the benefits of this implementation are:

Not only can it be translated, but also the json used for translation is cached on the page, which is local data. combobox can directly use this json without the need for remote

// 1. Verify that the row verification is successful. if it passes, Stop editing and set editIndex to undefined function endEditing () {if (editIndex = undefined) {return true} if ($ ('# dispatches_details '). datagrid ('validaterow', editIndex) {// The following method is used for translation on the official website, it's a small trick. // var ed =$ ('# dispatches_details '). datagrid ('getedit', {index: editIndex, field: 'reason '}); // var reason = Response (ed.tar get ). combobox ('gettext'); // $ ('# dispatches_details '). datagrid ('getrows ') [editIndex] ['reasonder'] = reason; // endEdit is interpreted as follows: finishing editing but before destroying editors // that is, editing is completed, however, the editor has not been released, that is, the value in rows, such as combobox, is still value, rather than text $ ('# dispatches_details '). datagrid ('enabled', editIndex); // you need to save var row =$ ('# dispatches_details') for each endEditing operation '). datagrid ('getrows ') [editIndex]; if (row) {// prevents non-editing, directly accept (), may be null // directly uploads the json to the background, send a Mao form jsonArr. splice (editIndex, 1, $. toStr (row);} editIndex = undefined; return true;} else {return false ;}}


Here we use a method of operating array in js -- splice. Below is a description of the method referenced from w3school. Note that this method will change the original array, different from slice.

Syntax

arrayObject.splice(index,howmany,item1,.....,itemX)
Parameters Description
Index Required. Integer that specifies the position of the added/deleted project. A negative number can be specified from the end of the array.
Howmany Required. The number of projects to delete. If it is set to 0, the project will not be deleted.
Item1,..., itemX Optional. Add a new project to the array.

Return Value

Type Description
Array Contains the new array of the deleted project, if any.

JsonArr. splice (editIndex, 1, $. toStr (row); in this way, the array element can be replaced!




How to save data when editing rows in easyui datagrid

Shout, save! Then, execute event processing.
 
How can we edit and save data in the datagrid in winfrom?

Private void button#click (object sender, System. EventArgs e)
{
String cnStr = "Password = qq; Persist Security Info = True; User ID = sa;" + "Initial Catalog = Northwind; Data Source = CHQHAO ";
SqlConnection cn = new SqlConnection (cnStr );
String sqlStr = "SELECT * FROM Employees ";
MyDataAdapter = new SqlDataAdapter (sqlStr, cn );
SqlCommandBuilder cb = new SqlCommandBuilder (myDataAdapter );
Ds = new DataSet ();
MyDataAdapter. Fill (ds, "Employees ");
// Bind the MERs table in the dataset to the DataGrid Control.
DataGrid1.SetDataBinding (ds, "Employees ");
}

Private void button2_Click (object sender, System. EventArgs e)
{
MyDataAdapter. Update (ds, "Employees ");
MessageBox. Show ("saved successfully! ");
}
I have something wrong with editing that piece of code. If it fails to achieve the expected results, I will not try again, so as not to make a smile. Haha.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.