I need to reacreate the model browser structure, but so far I haven't been sucessfull, I'm trying to join the parents and childs to reacrete the structure in the viewer.
One of my requirements is to use the model.sdb database, so I can't use the tree structure inside the viewer. (Viewer API) OR the model derivative API
So anything between a SQL query and a linq expression would solve my problem.
Thanks!
var queryBranches = universe.Where(o => o.ObjectsEav.Any(eav => eav.Attribute.Name == "child" && eav.Attribute.Category == "__child__"));
var queryLeafs = universe.Where(o => o.ObjectsEav.Any(eav => eav.Attribute.Name == "parent" && eav.Attribute.Category == "__parent__")).Except(queryBranches);
//Get Structure
foreach (var leaf in leafs)
{
var leafAttr = leaf.ObjectsEav.FirstOrDefault(eav => eav.Attribute.Name == "parent");
if (leafAttr == null)
leafAttr = leaf.ObjectsEav.FirstOrDefault(eav => eav.Attribute.Name == "parent");
...
}
One of my requirements is to use the model.sdb database, so I can't use the tree structure inside the viewer. (Viewer API) OR the model derivative API.
You can either query the property db in client browser or in your backend.
Alternatively try model.getPropertyDb().executeUserFunction():Promise to execute function in worker thread against the PropertyDatabase instance:
executeUserFunction(function(pdb) {
var dbId = 1;
pdb.enumObjectProperties(dbId, function(propId, valueId) {
// do stuff
});
})
Related
I have an array of json objects, and I want to be able to show either all of them, or remove some of them by filtering them by a key value.
I achieved this by creating a new constant:
const filtered = data.filter((item) => item.highVariance === false);
And a different constant:
const showHighVar = isHighVar ? data : filtered;
And then I have a checkbox that lets me toggle the shotHighVar constant in:
input type="checkbox" onChange={() => setHighVar(!isHighVar)}/>
In order to map it later in code:
{sorted(showHighVar).slice(0, 25 * pageIndex).map((x) => (...))}
But it seems to me like there should be a better way of doing this, but I can't figure it out.
There is nothing wrong with the way you are doing it. the one thing that i would change is that instead of creating filtered variable all the time just filter the data when isHighVar is false. So your code should look something like this -
const showHighVar = isHighVar ? data : data.filter((item) => item.highVariance === false);
{sorted(showHighVar).slice(0, 25 * pageIndex).map((x) => ( .....))}
Or when you are running the map function after sorting and slicing. just add a if statement in map function and check if isHighVar is false then return null else do whatever you are doing.
eg.
{sorted(data).slice(0, 25 * pageIndex).map((x) => {
if(isHighVar===false && x.highVariance!==false){
return null;
}
....
})}
Answer in
How to replace remapColums with remapColumnsByName in free jqgrid
contains code to save and restore jqgrid column order.
It contains method to restore columns state:
var restoreColumnState = function (colModel) {
var colItem, i, l = colModel.length, colStates, cmName,
columnsState = getObjectFromLocalStorage(myColumnStateName);
if (columnsState) {
colStates = columnsState.colStates;
for (i = 0; i < l; i++) {
colItem = colModel[i];
cmName = colItem.name;
if (cmName !== "rn" && cmName !== "cb" && cmName !== "subgrid") {
colModel[i] = $.extend(true, {}, colModel[i], colStates[cmName]);
}
}
}
return columnsState;
};
This method causes invalid data posting from inline edit if new column is defined in server side.
jqgrid is populated from remote json data array. In this array columns must be the same as in column state.
If columns state is saved and new column is added to jqgrid in server code,
colStates[cmName] value is undefined.
This code causes new column to be added to end of jqgrid columns. However, in json data array it appears in the column as defined in server.
On inline edit, if row is saved, wrong values are assigned to form fields and invalid values are passed to server.
I tried to fix it adding colStates[cmName] !== undefined check:
if (cmName !== "rn" && cmName !== "cb" && cmName !== "subgrid" && colStates[cmName] !== undefined) {
but problem persists.
How to fix this that if new column is added to jqgrid colmodel in server, restoring column state allows to save correct data?
New column which is not found in saved columns list should appear in the same relative position as it is defined in colmodel. Column order shoudl corrspond to remote data from server.
Update
ColModel is defined in Razor view in variable cm
<script>
var
$grid,
myColumnsState,
isColState,
myColumnStateName;
$(function () {
var cm= #Html.Raw(Model.GetColModel());
$grid = $("#grid");
myColumnStateName = #Model.ColumnStateName();
myColumnsState = restoreColumnState(cm, myColumnStateName);
isColState = typeof (myColumnsState) !== 'undefined' && myColumnsState !== null;
$grid.jqGrid({
page: isColState ? myColumnsState.page : 1,
sortname: isColState ? myColumnsState.sortname : "",
sortorder: isColState ? myColumnsState.sortorder : "",
....
</script>
I know the problem very good! One need to implement some kind of validating checks of the previously saved state of the grid before the usage. The deepness of checks could depend on the exact requirements of your application and from the information which one knows exactly. The most opened and unclear thing: should one make some correction/fixing of the previously saved state or should one discard the state on the first small error? The answer on the question depends on the project where jqGrid are used. Deep fixing could include fixing of sorting parameter and modifying previously saved filter. Another example: the state could include ids of selected rows, but the fixing of the part of the state could be bad idea in the common case. One loading of the data could imply one setting of selected rows, but loading of another data (unfiltered for example) could do have the rows and the rows should be do selected. There are no best choice in the case, all depends on the exact project requirements. In any way the implementation of the state validation/fixing isn't a simple code.
Only because of the complexity of the problems of validation of previously saved state and the existence of different scenarios of validation I didn't implemented such feature in free jqGrid. Any good implementation needs time and the resulting code will be not simple. It will have some options for some typical scenarios. I would like to implement the feature in the future, but I just didn't found the time for the implementation, because I have to do my main job to earn money for my family and I still try to help other people in the community who have small, but important, for the person, problems with jqGrid of free jqGrid.
That's a pretty long winded statement.
I'm building a faceted search which implements WebAPI in .Net and utilizes Knockout on the front end. My search response includes two lists of objects, the Resources (object with data for presentation) and Resource Facets (array of strings).
\"ResourceFacets\": [\r\n \"Book\",\r\n \"Video\",\r\n \"DVD\",\r\n \"eBook\",\r\n \"Audio\"\r\n ]\r\n}"
My ViewModel contains both the facets and the resources along with a presentation object to handle a custom row count:
function ViewModel() {
this.facets = ko.observableArray(results.ResourceFacets);
this.resources = ko.observableArray(results.ResourceResults);
this.resourceRows = ko.computed(function() {
var rows = [],
rowIndex = 0,
itemsPerRow = 2;
var resourceList = this.resources();
for (var index = 0; index < resourceList.length; index++) {
if (!rows[rowIndex]) {
rows[rowIndex] = [];
}
rows[rowIndex].push(resourceList[index]);
if (rows[rowIndex].length == itemsPerRow) {
rowIndex++;
}
}
return rows;
});
};
This allowed me to create a dynamic list of checkboxes to handle the facets and also display the resource results. What I'm trying to do now is add a Select All checkbox which will, by default, select all the boxes. From other examples I've seen, my understanding is that I need an observable property, something like "Selected", on that ResourceFacet. I just feel like that is too much that the API needs to know about my presentation.
So my question is how can I avoid having to add a "selected" bool value to the ResourceFacets but still be able to select all checkboxes or deselect the "All" checkbox when a user deselects a facet?
You can keep the list of booleans necessary to track the selection on a separate member of your view model, in addition to facets and resources. Just create a new observableArray of booleans of the same size of facets and bind those values to the checkboxes.
Another solution is to create the objects necessary to bind the checkboxes on the fly, based on results.ResourceFacets, keeping your API clean. For example:
var realModel = [];
for (var i = 0; i < results.ResourceFacets; i++) {
realModel.push({ name: results.ResourceFacets[i], chkBoxVal: ko.observable(false) });
}
this.facets = ko.observableArray(realModel);
Is there a way to store multiple items in a shared object? I want to store the score and it's profile name at the same time in an android game.
here is my code so far.
if(playerScore > lvl1Score.data.score1 || lvl1Score.data.score1 == 0)
{
lvl1Score.data.score5 = lvl1Score.data.score4;
lvl1Score.data.score4 = lvl1Score.data.score3;
lvl1Score.data.score3 = lvl1Score.data.score2;
lvl1Score.data.score2 = lvl1Score.data.score1;
lvl1Score.data.score1 = playerScore;
lvl1Score.data.scoreName1 = curUser;
lvl1Score.flush();
}
scoreBoard.one.text = String(lvl1Score.data.score1);
can someone please help me?
You can store Objects in a shared object.
Following your example, this may look as follows:
lvl1Score.data.score5 = { score: 2, profileName: "some_score" };
I have 20 fields on form, how to update fields modified by user during runtime and how to check which fields have changed so that i can only update those values in table using LINQ. I am working on windows application using C# and VS2010
Please refer the code (Currently i am passing all values, i knw this is not the correct way)
private void UpdateRecord(string groupBoxname)
{
using (SNTdbEntities1 context = new SNTdbEntities1())
{
{
Vendor_Account va = new Vendor_Account();
var Result = from grd in context.Vendor_Account
where grd.Bill_No == dd_billNo.Text
select grd;
if (Result.Count() > 0)
if ((dd_EditProjectName.Text!= "Select") && (dd_billNo.Text!="Select") && (dd_editVendorName.Text!="Select"))
{
foreach (var item in Result)
{
va.Account_ID = item.Account_ID;
}
va.Amount_After_Retention = Convert.ToDecimal(txt_AD_AfterRet.Text);
va.Balance = Convert.ToDecimal(txt_AD_Balance.Text);
va.Bill_Amount = Convert.ToDecimal(txt_AD_BillAmount.Text);
va.Bill_Date = Convert.ToDateTime(dt_AD_BillDate.Text);
va.Bill_No = dd_billNo.Text;
va.Comments = txt_AD_Comments.Text;
va.Paid_Till_Date = string.IsNullOrEmpty(txt_AD_Paid.Text)?0:Convert.ToDecimal(txt_AD_Paid.Text);
va.Project_Name = dd_EditProjectName.Text;
va.Retention_Perc = Convert.ToDecimal(txt_retPerc.Text);
va.Amount_After_Retention = Convert.ToDecimal(txt_AD_AfterRet.Text);
va.Vendor_Name = dd_editVendorName.Text;
va.Vendor_Code = txt_AD_Code.Text;
context.Vendor_Account.ApplyCurrentValues(va);
//context.Vendor_PersonalInfo.AddObject(vpi);
context.SaveChanges();
MessageBox.Show("Information Updated Sucessfully!");
lbl_Warning.Text = "";
entityDataSource1.Refresh();
}
else
{
MessageBox.Show("Vendor Name,Project Name and Bill No cannot be blank!!");
}
}
}
}
Entity framework will do that task.
Since you didn't provide any code, I cannot be precise about the answer but please check those links:
http://msdn.microsoft.com/en-us/library/aa697427(v=vs.80).aspx, section:Manipulating Data and Persisting Changes
http://www.codeproject.com/KB/database/sample_entity_framework.aspx
Note that the SaveChanges() function will update any modification done the records in EF.
Create some field dublicates, and compare value from the form element with the local dublicate, if it was changed than update it.