This is a migrated thread and some comments may be shown as answers.

Can I proceed with the QUERY only?

3 Answers 42 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
NHJ
Top achievements
Rank 1
NHJ asked on 20 Dec 2019, 05:00 PM
Hello,

I'm using the create, update, etc. features of transport very well.

But there is a problem.

I wanted to proceed with a simple Insert, Update, but the above create, update has the condition that the datasource should have a change.


I've looked up the dataSource.query () method so is this correct?

However, the only example is select, and I do not know the configuration that proceeds to create / update with the data I prepared arbitrarily.


If this is possible please give me some good sample code.

3 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 24 Dec 2019, 09:08 AM

Hi Nam,

It is correct that the Kendo UI DataSource would initiate the create/update requests only when a change in the data source is present. To my assumptions, it appears that you are adding an item to the data source programmatically, is that correct? If so, what is the approach used to add the item to the data of the data source? 

As per the query() method, you would be able to send additional data to the back-end, however, this would make the request go to the ActionMethod that is responsible for the Read of the data source. Therefore, you would have to implement the logic for saving an item within the Read method which would mix the two and unexpected behavior might occur.

What I can recommend is that you initiate a custom ajax request and send the additional data to the back-end. Whenever the item of interest is saved, within the success callback of the ajax request, call the read() method of the data source. It would make a request to take the updated items from the database.

Let me know in case this is not the scenario you are willing to achieve. It would be very helpful to me if you could provide additional details on the case.

 

Regards,
Tsvetomir
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
NHJ
Top achievements
Rank 1
answered on 25 Dec 2019, 04:52 AM
Thank you for your response.

First of all, it makes sense to explain my intentions again.

I only know two ways to do things like Insert () or Update ().
1. saveChanges ()
2. sync ()

If I want to perform one insert, I have to go through four steps.

1. Create a datasource (new DataSource ..)

2. Set the URL and parameters in the data source

3. Make changes to the data source

4. Run saveChanges ().


This is a very cumbersome and cumbersome task.


Here's how I want it:


Like how to use dataSource.read ()

dataSoruce.insert (parameter)

or

dataSource.update (parameter)

Is to run that CRUD already prepared with a short command.


But unfortunately I know I can't use it that way except read ().
(Because it is based on changes in the data source, is that correct?)



Please let me know if there is a way to do the query immediately like I wrote less.
0
Accepted
Tsvetomir
Telerik team
answered on 25 Dec 2019, 11:39 AM

Hi Nam,

In general, the Kendo UI DataSource is designed for usage over an extended period of time. Therefore, it should be created only once at the beginning of the page creation and use it throughout. Therefore, if you create and set up the data source at the very beginning for CRUD operations e.g. setting the read URL, update URL, create URL, etc. you could insert an item and save it as follows:

dataSource.insert({prop1: "prop", prop2: "prop2"});
dataSource.sync();

Since the data source is an object, its reference could be saved in a variable. This variable could be used anywhere on the page(depends on the scope in which the data source is declared).

It is not needed to create a new data source for every item that you would like to save to the database. It is correct that the data source should have an item marked as dirty or have changes in order to trigger the update or create.

Alternatively, if you would like to simply send a single item to the server-side, you could do so by performing a custom ajax request. Pass the item inside the "data" option of the request and save it in the database on the server-side. 

 

Regards,
Tsvetomir
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Data Source
Asked by
NHJ
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
NHJ
Top achievements
Rank 1
Share this question
or