How to apply bootgrid filter? - jquery-bootgrid

I have a bootgrid table with large number of rows. Is it possible to apply filter on the table?
e.g. each row has an attribute, say type. I want to display type="A" rows only.
many thx
steve

Try this solution:
Enable Ajax ajax : true.
Add this custom search value to your ajax requests like this:
$('#grid').bootgrid({
ajax : true,
url : '/this/is/the/ajax/url',
otherStuff : ... ,
requestHandler : function (request) {
request.searchVal = $('#type').val("A");
return request;
}
});

Related

Subscribing to valueChanges for multiple fields is causing performance issue in reactive form angular 2

I have more than 50 fields those are input text and dropdowns in the reactive form. The fields are dependent to each other's value changes in order to trigger validation and to display related field after the selection.
I subscribed to the value changes in ngOnInit() as below:
ngOnInit() {
this.setPageValidation();
}
setPageValidation() {
this.NameSubscription = this.FormGroup.get('personnel').get('name').valueChanges.subscribe(data
=> {
this.enableOrders();
});
this.StateSubscription = this.FormGroup.get('personnel').get('state').valueChanges.subscribe(data
=>
{
this.enableAccount();
});
// more value changes subscription like 40 fields ............................
}
While loading the form, it is taking longer time to load due to subscribing for the value changes when the form loads.
I tried implementing it to move the code to ngOnChanges() but it is not triggering the enable and display of other fields depending on it's initial value that are filled from the table if there are values for those fields. It is just populating the first field and the rest does not display depending upon on its value.
I would like to thank you in advance. I really appreciate your help if there is any best approach to it to resolve without performance issue.
You can do with a single subscription.
this.personnelSubscription =
this.Formgroup.get('personnel').valueChanges.subscribe(data => {
if (data) {
//Console log the data here. It will print the formGroup of personnel
// then select the control and add your validations
// like this data.controls.state
}
})

Passing multiple values from Ajax to MVC Controller then build a dynamic query string using ExecuteQuery to get Json result

So A little bit background here:
I have built about 9 cascaded dropdowns/listboxs in the webpage and user can select depending on what they like from step-1 to the step-final. After that, they click submit button and I have built a collector to collect all of what they have selected and use Ajax to pass those parameters(and arrays, some of those are multi-selection)to MVC Controller.
The number of data back into the database is gigantic, if I don't set up any restrictions to get all of data in SQL database, that's going to be more than 4 millions of records in more than 15mins. So I can't use any typical approaches like I set up repositories in model and retrieve data in controller using linq, this is the way how I built those dropdowns and listboxs. But in these situation, this method will throw OutOfMemoryExecption and Json will throw maxJsonLength error to me and based on the time effecive, I can't take any single process more than seconds.
One thought about this solution is that, I get data only from what exactly user selected. Actually this is also how it works in sql database. Because no one wants to get everything in this database, they just want what exact field they want to see in this data view. If there are some solutions that I can directly talk from controller to sql database. I can put those selections in a query and pass it to sql database, then I return result only depends on what this query says. That will be very efficient.
Code:
So I wrote Ajax to pass those vars to controller:
$("#submit").click(function(){
$.ajax({
cache: false,
type: "GET",
url: "url/url",
data: {
"DateFrom": datefrom,
"DateTo": dateto,
"dropdownselectioninstep1": step1,
"dropdownselectioninstep2": step2,
"multiselectionstep3": intarraystep3,
"multiselectionstep4": stringarraystep4,
//....step 5,6,7,8,9,etc...
},
success: function (data) {...}
});
});
New Update - So I took these suggestions below and did some research online, I came up with some ideas that can deal with this giant database view. So the idea is writing a query that directly talks to SQL in controller so that I can get very detailed data using those values that I collected from Ajax, but I came across with some problems because of my lack of C# knowledge... Here's my controller:
public ActionResult GetAllCases(string DateFrom, string DateTo, string step1, string step2, int[] intarraystep3, string [] stringarraystep4, ...)
{
// So I worte a long query to match the dynamic needs from those dropdown/listbox
//selections and if it can be passed through database directly,
//I can return very specific data set instead of waiting SQL to
// process the full millions of records in database.
var query = "SELECT" + step1 + "," + step2 + "FROM view_cases as w WHERE " + step2 + " IN(" + intarraystep3 + ") AND" w.date "BETWEEN '" + DateFrom + "' AND '" + DateTo + "'";
var result = _dataContext.ExecuteQuery<// what things do I need to put here?>(#query).ToList();
return Json(result, JsonRequestBehavior.AllowGet);
}
I realized when I put a break point in this class, I did see this query passed to SQL, and successfully returned the correct amount of data set in Locals window. But If I put my view view_cases in var result = _dataContext.ExecuteQuery<view_cases>(#query).ToList(); It returns all of the columns in this view but not returning the columns that I put in the SELECT clause in query. So I guess I must missed some steps or should I create a model class or something like that?
If you have any question about what I'm trying to explain or any ideas about this question, drop a line to me. Any comment will be highly appreciated!
Thank you
Kevin.
you can create a queryObject and generate the sql query base on the queryObject
$.ajax({
cache: false,
type: "GET",
url: "url/url",
data: {
criteria: {
"DateFrom": datefrom,
"DateTo": dateto,
"dropdownselectioninstep1": step1,
"dropdownselectioninstep2": step2,
"multiselectionstep3": intarraystep3,
"multiselectionstep4": stringarraystep4,
//....step 5,6,7,8,9,etc...
}
},
success: function (data) {...}
});
public ActionResult GetAllCases(QueryObject criteria)
{
// do not do sql query from your controller, your controller should be
// as thin as possible, use a QueryService to encapsulate the query logic
queryService.queryAllCase(criteria);
}
public class QueryObject {
public DateTime DateFrom { get; set; }
...
}
if the data is gigantic, conside to paginate your result.

The parameter of serializeDelData callback contains id field only

I use jgGrid 4.5.4. When a user presses the Delete button, I need to send two pieces of information to the server: the record ID, and record version (for optimistic locking). I know that serializeDelData callback can be used for this purpose:
serializeDelData:serializeDelDataCallback
...
function serializeDelDataCallback(data) {
// The "data" argument has "id" and "oper" fields only! Where can I get other fields of the current grid row?
...
return $.param(modifiedData);
}
However, the argument of the serializeDelData callback contains id and oper fields only. I use a similar callback for posting new and updated records - that callback provides all fields of the current row.
Where can I get other fields of the current grid row in the serializeDelData callback? (I need to get the row version which is a hidden field in the grid.)
If you use optimistic locking then the rows of the grid contains probably record version column.
The most easy way to onclickSubmit callback (see the documentation) for example in the following form
onclickSubmit: function (options, rowid) {
return {
rowVer: $(this).jqGrid("getCell", rowid, "rowVersion")
};
}
In the above code I suppose that you have column with the name rowVersion which hold record version which you need to send as rowVer param. In general you can use getCell in the same way inside of serializeDelData, but onclickSubmit seems me more simple. The returned properties of onclickSubmit will be combined with the standard parameters used by Delete, so you should have all information which you need.

how to change a partiuclar model data in backbone.js

e.g. I have a model in Backbone.js Content and collection of this model Contents.
the model has attribute
{ id:1 , name:'rahul ',age: 27 }
now if i want to update the model with id=1 in my collection then what will be the code ?
e.g i want to update name from rahul to mehta .
Content = Backbone.Model.extend({
initialize: function() {
}
});
Contents = Backbone.Collection.extend({
model : Content,
initialize: function(models, args) {
console.log('in contents'+this.length);
}
});
what will be the code for this .?
How i will get the model from my collection of models ?
{id:1,name:mehta ,age : 27 }
and then i need to update the content of that ?should i need to change the complete data to the model or part of data only i need to update ?
For your first question:
var rahul = contents.get(1);
rahul.set({name: "mehta"});
Second question: this within initialize would be the collection.
Last question: you update what you want to update on the model using the set function of the model.
Please read the documentation: http://documentcloud.github.com/backbone/

Magento Validate Form Only Certain Fields

I have a function to validate all fields in a form:
validateForm: function() {
var validator = new Validation(this.form);
validator.validate();
}
There are two controls. First control need to validate only a,b,c fields. Second control need to validate only d,e,f fields. How can I achieve this?
To validate only a certain field, you can use:
Validation.validate(document.getElementById(id));

Resources